class EntitySchema::Fields::Object

Associated object

Attributes

mapper[R]
serializer[R]

Public Class Methods

new(specification) click to toggle source
Calls superclass method EntitySchema::Fields::Abstract::new
# File lib/entity_schema/fields/object.rb, line 9
def initialize(specification)
  @mapper     = specification[:mapper]
  @serializer = specification[:serializer]
  super(specification)
end

Public Instance Methods

get(obj) click to toggle source
# 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) click to toggle source
# File lib/entity_schema/fields/object.rb, line 20
def serialize(obj, output)
  return unless given?(obj)
  value = read(obj)
  output[src_key] = (value.is_a?(Hash) ? value : unwrap(value))
end

Private Instance Methods

map(hash) click to toggle source
# File lib/entity_schema/fields/object.rb, line 30
def map(hash)
  mapper.call(hash)
end
unwrap(object) click to toggle source
# File lib/entity_schema/fields/object.rb, line 34
def unwrap(object)
  serializer.call(object)
end