Class: Representable::Hash::Binding

Inherits:
Binding
  • Object
show all
Defined in:
lib/representable/hash/binding.rb

Direct Known Subclasses

Collection, Hash, YAML::Binding

Defined Under Namespace

Classes: Collection, Hash

Instance Attribute Summary

Attributes inherited from Binding

#represented, #user_options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Binding

#[], #array?, #as, build, #compile_fragment, #default_for, #evaluate_option, #get, #getter, #has_default?, #initialize, #name, #parse_filter, #read_fragment, #render_filter, #render_fragment, #representable?, #representer_module, #representer_module_for, #set, #setter, #skipable_empty_value?, #typed?, #uncompile_fragment, #write_fragment

Constructor Details

This class inherits a constructor from Representable::Binding

Class Method Details

.build_for(definition, *args) ⇒ Object

TODO: remove default arg.


6
7
8
9
10
# File 'lib/representable/hash/binding.rb', line 6

def self.build_for(definition, *args)  # TODO: remove default arg.
  return Collection.new(definition, *args)  if definition.array?
  return Hash.new(definition, *args)        if definition.hash?
  new(definition, *args)
end

Instance Method Details

#deserialize_methodObject


26
27
28
# File 'lib/representable/hash/binding.rb', line 26

def deserialize_method
  :from_hash
end

#read(hash) ⇒ Object


12
13
14
15
16
# File 'lib/representable/hash/binding.rb', line 12

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.

  hash[as] # fragment
end

#serialize_methodObject


22
23
24
# File 'lib/representable/hash/binding.rb', line 22

def serialize_method
  :to_hash
end

#write(hash, fragment) ⇒ Object


18
19
20
# File 'lib/representable/hash/binding.rb', line 18

def write(hash, fragment)
  hash[as] = fragment
end