Class: Bumblebee::Mutator
- Inherits:
-
Object
- Object
- Bumblebee::Mutator
- Includes:
- Types
- Defined in:
- lib/bumblebee/mutator.rb
Overview
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.’
Defined Under Namespace
Modules: Types
Constant Summary
Constants included from Types
Instance Attribute Summary collapse
-
#converter ⇒ Object
readonly
Returns the value of attribute converter.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(arg, resolver: Objectable.resolver) ⇒ Mutator
constructor
A new instance of Mutator.
- #set(object, key, val) ⇒ Object
Constructor Details
#initialize(arg, resolver: Objectable.resolver) ⇒ Mutator
Returns a new instance of Mutator.
21 22 23 24 25 26 27 |
# 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 |
Instance Attribute Details
#converter ⇒ Object (readonly)
Returns the value of attribute converter.
19 20 21 |
# File 'lib/bumblebee/mutator.rb', line 19 def converter @converter end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
19 20 21 |
# File 'lib/bumblebee/mutator.rb', line 19 def type @type end |
Instance Method Details
#set(object, key, val) ⇒ Object
29 30 31 32 33 |
# File 'lib/bumblebee/mutator.rb', line 29 def set(object, key, val) return object if ignore? resolver.set(object, key, converter.convert(val)) end |