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.

Instance Method Summary collapse

Constructor Details

#initialize(definition, twin, value = nil) ⇒ PropertyProcessor

Returns a new instance of PropertyProcessor.



7
8
9
10
11
# File 'lib/disposable/twin/property_processor.rb', line 7

def initialize(definition, twin, value=nil)
  value ||= twin.send(definition.getter)
  @definition = definition
  @value      = value
end

Instance Method Details

#call(&block) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/disposable/twin/property_processor.rb', line 13

def call(&block)
  if @definition[:collection]
    collection!(&block)
  else
    property!(&block)
  end
end