Class: EntitySchema::Fields::Object
- Defined in:
- lib/entity_schema/fields/object.rb
Overview
Associated object
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Abstract
#name, #specification, #src_key
Instance Method Summary collapse
- #get(obj) ⇒ Object
-
#initialize(specification) ⇒ Object
constructor
A new instance of Object.
- #serialize(obj, output) ⇒ Object
Methods inherited from Abstract
#given?, #public_get, #public_set, #set
Constructor Details
#initialize(specification) ⇒ Object
Returns a new instance of Object.
9 10 11 12 13 |
# File 'lib/entity_schema/fields/object.rb', line 9 def initialize(specification) @mapper = specification[:mapper] @serializer = specification[:serializer] super(specification) end |
Instance Method Details
#get(obj) ⇒ Object
15 16 17 18 |
# File 'lib/entity_schema/fields/object.rb', line 15 def get(obj) value = read(obj) value.is_a?(Hash) ? write(obj, map(value)) : value end |
#serialize(obj, output) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/entity_schema/fields/object.rb', line 20 def serialize(obj, output) return unless given?(obj) value = read(obj) return output[src_key] = value if value.is_a?(Hash) output[src_key] = unwrap(value) end |