class Bumblebee::Mutator
A Mutator
is a composition of a converter with hash value setting. It can be a straight converter, or it can be new types which are not directly defined as 'converters.'
Attributes
converter[R]
resolver[R]
type[R]
Public Class Methods
new(arg, resolver: Objectable.resolver)
click to toggle source
# File lib/bumblebee/mutator.rb, line 21 def initialize(arg, resolver: Objectable.resolver) @resolver = resolver @converter = arg.nil? || mutator?(arg) ? NullConverter.new : SimpleConverter.new(arg) @type = mutator?(arg) ? Types.const_get(arg.to_s.upcase.to_sym) : nil freeze end
Public Instance Methods
set(object, key, val)
click to toggle source
# File lib/bumblebee/mutator.rb, line 29 def set(object, key, val) return object if ignore? resolver.set(object, key, converter.convert(val)) end
Private Instance Methods
ignore?()
click to toggle source
# File lib/bumblebee/mutator.rb, line 39 def ignore? type == IGNORE end
mutator?(arg)
click to toggle source
# File lib/bumblebee/mutator.rb, line 43 def mutator?(arg) return false unless arg.is_a?(String) || arg.is_a?(Symbol) Types.constants.include?(arg.to_s.upcase.to_sym) end