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
151 152 153 |
# File 'lib/representable/binding.rb', line 151 def create_object(fragment) instance_for(fragment) or class_for(fragment) end |
#deserialize(data) ⇒ Object
144 145 146 147 148 149 |
# File 'lib/representable/binding.rb', line 144 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, @user_options) end end |
#serialize(object) ⇒ Object
138 139 140 141 142 |
# File 'lib/representable/binding.rb', line 138 def serialize(object) return object if object.nil? super.send(serialize_method, @user_options.merge!({:wrap => false})) # TODO: pass :binding => self end |