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

#array, #cached_representer, #getter, #has_default, #name, #representable, #represented, #setter, #skip_filters, #typed, #user_options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Binding

#[], #as, build, #compile_fragment, #default_for, #evaluate_option, #get, #initialize, #parse_filter, #read_fragment, #render_filter, #render_fragment, #representer_module_for, #set, #skipable_empty_value?, #uncompile_fragment, #update!, #write_fragment

Methods included from Binding::Factories

#deserializer, #deserializer_class, #populator, #populator_class, #serializer, #serializer_class

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
11
# File 'lib/representable/hash/binding.rb', line 6

def self.build_for(definition, *args)  # TODO: remove default arg.
  # puts "@@@build@@ #{definition.inspect}"
  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



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

def deserialize_method
  :from_hash
end

#read(hash) ⇒ Object



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

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



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

def serialize_method
  :to_hash
end

#write(hash, fragment) ⇒ Object



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

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