Class: EntitySchema::Fields::Collection
- Defined in:
- lib/entity_schema/fields/collection.rb
Overview
associated array of objects
Instance Attribute Summary
Attributes inherited from Abstract
#name, #specification, #src_key
Instance Method Summary collapse
Methods inherited from Object
Methods inherited from Abstract
#given?, #initialize, #public_get, #public_set
Constructor Details
This class inherits a constructor from EntitySchema::Fields::Object
Instance Method Details
#get(obj) ⇒ Object
16 17 18 19 |
# File 'lib/entity_schema/fields/collection.rb', line 16 def get(obj) values = read(obj) values&.first.is_a?(Hash) ? write(obj, map(values)) : values end |
#serialize(obj, output) ⇒ Object
21 22 23 24 |
# File 'lib/entity_schema/fields/collection.rb', line 21 def serialize(obj, output) values = read(obj) output[src_key] = (values.first.is_a?(Hash) ? values : unwrap(values)) end |
#set(obj, collection) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/entity_schema/fields/collection.rb', line 9 def set(obj, collection) case collection when Array, nil then super else raise ArgumentError, 'collection field must be Array' end end |