Class: Disposable::Twin::PropertyProcessor

Inherits:
Object
  • Object
show all
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

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