class Disposable::Twin::PropertyProcessor

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:

Public Class Methods

new(definition, twin, value=nil) click to toggle source
# 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

Public Instance Methods

call(&block) click to toggle source
# File lib/disposable/twin/property_processor.rb, line 14
def call(&block)
  if @definition[:collection]
    collection!(&block)
  else
    property!(&block)
  end
end

Private Instance Methods

collection!() { |nested_twin, i| ... } click to toggle source
# File lib/disposable/twin/property_processor.rb, line 23
def collection!
  (@value || []).each_with_index.collect { |nested_twin, i| yield(nested_twin, i) }
end
property!() { |twin| ... } click to toggle source
# File lib/disposable/twin/property_processor.rb, line 27
def property!
  twin = @value or return nil
  yield(twin)
end