Class: Representable::ObjectDeserializer

Inherits:
Object
  • Object
show all
Defined in:
lib/representable/deserializer.rb

Direct Known Subclasses

ObjectSerializer

Instance Method Summary collapse

Constructor Details

#initialize(binding, object) ⇒ ObjectDeserializer

dependencies: Def#options, Def#create_object, Def#get



26
27
28
29
# File 'lib/representable/deserializer.rb', line 26

def initialize(binding, object)
  @binding = binding
  @object  = object
end

Instance Method Details

#call(fragment) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/representable/deserializer.rb', line 31

def call(fragment)
  # TODO: this used to be handled in #serialize where Object added it's behaviour. treat scalars as objects to remove this switch:
  return fragment unless @binding.typed?

  if @binding.sync?
    # TODO: this is also done when instance: { nil }
    @object = @object.call # call Binding#get or Binding#get[i]
  else
    @object = @binding.create_object(fragment)
  end

  # DISCUSS: what parts should be in this class, what in Binding?
  representable = prepare(@object)
  deserialize(representable, fragment, @binding.user_options)
  #yield @object
end