class EntitySchema::Fields::Collection

associated array of objects

Public Instance Methods

get(obj) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
Calls superclass method
# 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

Private Instance Methods

map(hashes) click to toggle source
Calls superclass method
# File lib/entity_schema/fields/collection.rb, line 28
def map(hashes)
  hashes.map { |hash| super(hash) }
end
unwrap(objects) click to toggle source
Calls superclass method
# File lib/entity_schema/fields/collection.rb, line 32
def unwrap(objects)
  objects.map { |object| super(object) }
end