Class: NoSE::Serialize::EntityBuilder

Inherits:
Object
  • Object
show all
Includes:
Uber::Callable
Defined in:
lib/nose/serialize.rb

Overview

Reconstruct the fields of an entity

Instance Method Summary collapse

Instance Method Details

#call(_, fragment:, user_options:) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/nose/serialize.rb', line 188

def call(_, fragment:, user_options:, **)
  # Pull the field from the map of all entities
  entity_map = user_options[:entity_map]
  entity = entity_map[fragment['name']]

  # Add all fields from the entity
  fields = EntityFieldRepresenter.represent([])
  fields = fields.from_hash fragment['fields'],
                            user_options: { entity_map: entity_map }
  fields.each { |field| entity.send(:<<, field, freeze: false) }

  entity
end