Module: Representable::HashMethods

Included in:
JSON::Hash, XML::AttributeHash, XML::Hash
Defined in:
lib/representable/hash_methods.rb

Instance Method Summary collapse

Instance Method Details

#create_representation_with(doc, options, format) ⇒ Object



10
11
12
13
14
# File 'lib/representable/hash_methods.rb', line 10

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

#representable_attrsObject

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



4
5
6
7
8
# File 'lib/representable/hash_methods.rb', line 4

def representable_attrs
  attrs = super
  attrs << Definition.new(*definition_opts) if attrs.size == 0
  attrs
end

#update_properties_from(doc, options, format) ⇒ Object



16
17
18
19
20
21
# File 'lib/representable/hash_methods.rb', line 16

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