Class: Representable::JSON::HashBinding

Inherits:
JSONBinding show all
Defined in:
lib/representable/bindings/json_bindings.rb

Instance Attribute Summary

Attributes inherited from Binding

#definition

Instance Method Summary collapse

Methods inherited from JSONBinding

#initialize, #read, #write

Methods inherited from Binding

#initialize

Methods included from Binding::Hooks

#deserialize, #serialize

Constructor Details

This class inherits a constructor from Representable::JSON::JSONBinding

Instance Method Details

#deserialize_from(fragment) ⇒ Object



67
68
69
# File 'lib/representable/bindings/json_bindings.rb', line 67

def deserialize_from(fragment)
  fragment.each { |key, item_fragment| fragment[key] = deserialize(item_fragment) }
end

#serialize_for(value) ⇒ Object



60
61
62
63
64
65
# File 'lib/representable/bindings/json_bindings.rb', line 60

def serialize_for(value)
  # requires value to respond to #each with two block parameters.
  {}.tap do |hash|
    value.each { |key, obj| hash[key] = serialize(obj) }
  end
end