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) ⇒ PropertyProcessor

Returns a new instance of PropertyProcessor.



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

def initialize(definition, twin)
  @definition, @twin = definition, twin
end

Instance Method Details

#call(&block) ⇒ Object



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

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