Module: Representable::Hash::Collection

Includes:
Representable::Hash
Defined in:
lib/representable/hash/collection.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Representable::Hash

#from_hash, #to_hash

Class Method Details

.included(base) ⇒ Object



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

def self.included(base)
  base.class_eval do
    include Representable
    extend ClassMethods
    extend Representable::Hash::ClassMethods # ::representer_engine.
  end
end

Instance Method Details

#create_representation_with(doc, options, format) ⇒ Object



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

def create_representation_with(doc, options, format)
  bin   = representable_mapper(format, options).bindings.first
  bin.write(doc, represented)
end

#representable_attrsObject

FIXME: refactor Definition so we can simply add options in #items to existing definition.



33
34
35
36
37
# File 'lib/representable/hash/collection.rb', line 33

def representable_attrs
  attrs = super
  attrs << Definition.new(:_self, :collection => true) if attrs.size == 0
  attrs
end

#update_properties_from(doc, options, format) ⇒ Object



26
27
28
29
30
# File 'lib/representable/hash/collection.rb', line 26

def update_properties_from(doc, options, format)
  bin   = representable_mapper(format, options).bindings.first
  value = bin.deserialize_from(doc)
  represented.replace(value)
end