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) ⇒ Mutator
constructor
A new instance of Mutator.
- #set(object, key, val) ⇒ Object
Constructor Details
#initialize(arg) ⇒ Mutator
Returns a new instance of Mutator.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bumblebee/mutator.rb', line 21 def initialize(arg) if arg.nil? @type = nil @converter = ::Bumblebee::NullConverter.new elsif mutator?(arg) @type = ::Bumblebee::Mutator::Types.const_get(arg.to_s.upcase.to_sym) @converter = ::Bumblebee::NullConverter.new else @type = nil @converter = ::Bumblebee::SimpleConverter.new(arg) end 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
36 37 38 39 40 |
# File 'lib/bumblebee/mutator.rb', line 36 def set(object, key, val) return object if ignore? ::Bumblebee::ObjectInterface.set(object, key, converter.convert(val)) end |