Module: Representable::Binding::Object
- Includes:
- Prepare
- Included in:
- Hash::ObjectBinding, XML::ObjectBinding, YAML::ObjectBinding
- Defined in:
- lib/representable/binding.rb
Overview
Overrides #serialize/#deserialize to call #to_/from_. Computes :class in #deserialize. # TODO: shouldn’t this be in a separate module? ObjectSerialize/ObjectDeserialize?
Instance Method Summary collapse
Methods included from Prepare
Instance Method Details
#create_object(fragment) ⇒ Object
147 148 149 |
# File 'lib/representable/binding.rb', line 147 def create_object(fragment) instance_for(fragment) or class_for(fragment) end |
#deserialize(data) ⇒ Object
140 141 142 143 144 145 |
# File 'lib/representable/binding.rb', line 140 def deserialize(data) # DISCUSS: does it make sense to skip deserialization of nil-values here? create_object(data).tap do |obj| super(obj).send(deserialize_method, data, ) end end |
#serialize(object) ⇒ Object
134 135 136 137 138 |
# File 'lib/representable/binding.rb', line 134 def serialize(object) return object if object.nil? super.send(serialize_method, .merge!({:wrap => false})) # TODO: pass :binding => self end |