Class: Representable::Hash::PropertyBinding
- Includes:
- Binding::Object
- Defined in:
- lib/representable/bindings/hash_bindings.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Binding
Class Method Summary collapse
-
.build_for(definition, *args) ⇒ Object
TODO: remove default arg.
Instance Method Summary collapse
- #deserialize_from(fragment) ⇒ Object
- #deserialize_method ⇒ Object
- #read(hash) ⇒ Object
- #serialize_method ⇒ Object
- #write(hash, value) ⇒ Object
Methods included from Binding::Object
#create_object, #deserialize, #serialize
Methods inherited from Binding
#as, build, #compile_fragment, #get, #initialize, #read_fragment, #read_fragment_for, #representer_module_for, #set, #uncompile_fragment, #write_fragment, #write_fragment_for
Constructor Details
This class inherits a constructor from Representable::Binding
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Representable::Binding
Class Method Details
.build_for(definition, *args) ⇒ Object
TODO: remove default arg.
8 9 10 11 12 |
# File 'lib/representable/bindings/hash_bindings.rb', line 8 def self.build_for(definition, *args) # TODO: remove default arg. return CollectionBinding.new(definition, *args) if definition.array? return HashBinding.new(definition, *args) if definition.hash? new(definition, *args) end |
Instance Method Details
#deserialize_from(fragment) ⇒ Object
25 26 27 |
# File 'lib/representable/bindings/hash_bindings.rb', line 25 def deserialize_from(fragment) deserialize(fragment) end |
#deserialize_method ⇒ Object
33 34 35 |
# File 'lib/representable/bindings/hash_bindings.rb', line 33 def deserialize_method :from_hash end |
#read(hash) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/representable/bindings/hash_bindings.rb', line 14 def read(hash) return FragmentNotFound unless hash.has_key?(as) # DISCUSS: put it all in #read for performance. not really sure if i like returning that special thing. fragment = hash[as] deserialize(fragment) end |
#serialize_method ⇒ Object
29 30 31 |
# File 'lib/representable/bindings/hash_bindings.rb', line 29 def serialize_method :to_hash end |
#write(hash, value) ⇒ Object
21 22 23 |
# File 'lib/representable/bindings/hash_bindings.rb', line 21 def write(hash, value) hash[as] = serialize(value) end |