Class: Representable::Hash::PropertyBinding
- Inherits:
-
Binding
- Object
- SimpleDelegator
- Binding
- Representable::Hash::PropertyBinding
show all
- Defined in:
- lib/representable/bindings/hash_bindings.rb
Instance Attribute Summary
Attributes inherited from Binding
#represented, #user_options
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Binding
build, #compile_fragment, #deserialize, #get, #read_fragment, #read_fragment_for, #serialize, #set, #uncompile_fragment, #write_fragment, #write_fragment_for
Constructor Details
25
26
27
28
|
# File 'lib/representable/bindings/hash_bindings.rb', line 25
def initialize(*args)
super
extend ObjectBinding if typed?
end
|
Class Method Details
.build_for(definition, *args) ⇒ Object
TODO: remove default arg.
19
20
21
22
23
|
# File 'lib/representable/bindings/hash_bindings.rb', line 19
def self.build_for(definition, *args)
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
45
46
47
|
# File 'lib/representable/bindings/hash_bindings.rb', line 45
def deserialize_from(fragment)
deserialize(fragment)
end
|
#read(hash) ⇒ Object
30
31
32
33
34
35
|
# File 'lib/representable/bindings/hash_bindings.rb', line 30
def read(hash)
return FragmentNotFound unless hash.has_key?(from)
fragment = hash[from]
deserialize_from(fragment)
end
|
#serialize_for(value) ⇒ Object
41
42
43
|
# File 'lib/representable/bindings/hash_bindings.rb', line 41
def serialize_for(value)
serialize(value)
end
|
#write(hash, value) ⇒ Object
37
38
39
|
# File 'lib/representable/bindings/hash_bindings.rb', line 37
def write(hash, value)
hash[from] = serialize_for(value)
end
|