class Representable::Populator

populator skip_parse? –> return deserialize (this is where additional logic can happen, e.g. Object-HAL's collection semantics). parse_filter set

Public Class Methods

new(binding) click to toggle source
# File lib/representable/populator.rb, line 9
def initialize(binding)
  @binding = binding
end

Public Instance Methods

call(fragment, doc) click to toggle source

goal of this is to have this workflow apply-able to collections AND to items per collection, or for items in hashes.

# 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

Private Instance Methods

deserialize(fragment) { || ... } click to toggle source
# File lib/representable/populator.rb, line 31
def deserialize(fragment)
  return yield if @binding.evaluate_option(:skip_parse, fragment) # TODO: move this into Deserializer.

  # use a Deserializer to transform fragment to/into object.
  deserializer.call(fragment) # CollectionDeserializer/HashDeserializer/etc.
end
deserializer() click to toggle source
# File lib/representable/populator.rb, line 38
def deserializer
  @binding.deserializer
end