Class: Representable::Hash::PropertyBinding

Inherits:
Binding
  • Object
show all
Defined in:
lib/representable/bindings/hash_bindings.rb

Instance Attribute Summary

Attributes inherited from Binding

#lambda_context, #represented, #user_options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Binding

build, #compile_fragment, #definition, #deserialize, #get, #read_fragment, #read_fragment_for, #serialize, #set, #uncompile_fragment, #write_fragment, #write_fragment_for

Constructor Details

#initialize(*args) ⇒ PropertyBinding

FIXME. make generic.



25
26
27
28
# File 'lib/representable/bindings/hash_bindings.rb', line 25

def initialize(*args) # FIXME. make generic.
  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)  # 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



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) # DISCUSS: put it all in #read for performance. not really sure if i like returning that special thing.
  
  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