class Representable::Deserializer::Collection

Collection does exactly the same as Deserializer but for a collection.

Public Instance Methods

call(fragment) click to toggle source
# File lib/representable/deserializer.rb, line 83
def call(fragment)
  collection = [] # this can be replaced, e.g. AR::Collection or whatever.

  fragment.each_with_index do |item_fragment, i|
    # add more per-item options here!
    next if @binding.evaluate_option(:skip_parse, item_fragment) # TODO: pass in index!

    collection << deserialize!(item_fragment, i) # FIXME: what if obj nil?
  end

  collection # with parse_strategy: :sync, this is ignored.
end

Private Instance Methods

deserialize!(*args) click to toggle source
# File lib/representable/deserializer.rb, line 97
def deserialize!(*args)
  item_deserializer.call(*args)
end
item_deserializer() click to toggle source
# File lib/representable/deserializer.rb, line 101
def item_deserializer
  @item_deserializer = Deserializer.new(@binding)
end