Class: Disposable::Twin::PropertyProcessor
- Inherits:
-
Object
- Object
- Disposable::Twin::PropertyProcessor
- Defined in:
- lib/disposable/twin/property_processor.rb
Overview
This is similar to Representable::Serializer and allows to apply a piece of logic (the block passed to #call) to every twin for this property.
For a scalar property, this will be run once and yield the property’s value. For a collection, this is run per item and yields the item. :private:
Instance Method Summary collapse
- #call(&block) ⇒ Object
-
#initialize(definition, twin, value = nil) ⇒ PropertyProcessor
constructor
A new instance of PropertyProcessor.
Constructor Details
#initialize(definition, twin, value = nil) ⇒ PropertyProcessor
Returns a new instance of PropertyProcessor.
8 9 10 11 12 |
# File 'lib/disposable/twin/property_processor.rb', line 8 def initialize(definition, twin, value=nil) value ||= twin.send(definition.getter) # DISCUSS: should we decouple definition and value, here? @definition = definition @value = value end |
Instance Method Details
#call(&block) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/disposable/twin/property_processor.rb', line 14 def call(&block) if @definition[:collection] collection!(&block) else property!(&block) end end |