Sha256: ebe509bb51d43313211c66b8945cd2b7884e2ce3004cc0a1067d2ed255d4fa21
Contents?: true
Size: 872 Bytes
Versions: 11
Compression:
Stored size: 872 Bytes
Contents
# 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: class Disposable::Twin::PropertyProcessor def initialize(definition, twin, value=nil) value ||= twin.send(definition.getter) # DISCUSS: should we decouple definition and value, here? @definition = definition @value = value end def call(&block) if @definition[:collection] collection!(&block) else property!(&block) end end private def collection! (@value || []).each_with_index.collect { |nested_twin, i| yield(nested_twin, i) } end def property! twin = @value or return nil yield(twin) end end
Version data entries
11 entries across 11 versions & 1 rubygems