Class: Representable::Populator
- Inherits:
-
Object
- Object
- Representable::Populator
- Defined in:
- lib/representable/populator.rb
Overview
skip_parse? –> return deserialize (this is where additional logic can happen, e.g. Object-HAL’s collection semantics). parse_filter set
Direct Known Subclasses
Defined Under Namespace
Classes: Collection, Hash
Instance Method Summary collapse
-
#call(fragment, doc) ⇒ Object
goal of this is to have this workflow apply-able to collections AND to items per collection, or for items in hashes.
-
#initialize(binding) ⇒ Populator
constructor
rename to Deserializer?.
Constructor Details
#initialize(binding) ⇒ Populator
rename to Deserializer?
9 10 11 |
# File 'lib/representable/populator.rb', line 9 def initialize(binding) @binding = binding end |
Instance Method Details
#call(fragment, doc) ⇒ Object
goal of this is to have this workflow apply-able to collections AND to items per collection, or for items in hashes.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/representable/populator.rb', line 14 def call(fragment, doc) # the rest should be applied per item (collection) or per fragment (collection and property) if fragment == Binding::FragmentNotFound return unless @binding.has_default? value = @binding[:default] else # DISCUSS: should we return a Skip object instead of this block trick? (same in Binding#serialize?) value = deserialize(fragment) { return } # stop here if skip_parse? end value = @binding.parse_filter(value, doc) # parse_filter # set @binding.set(value) end |