class NoSE::Serialize::ModelBuilder
Public Instance Methods
call(_, input:, fragment:, **)
click to toggle source
# File lib/nose/serialize.rb, line 508 def call(_, input:, fragment:, **) model = input.represented entity_map = add_entities model, fragment['entities'] add_reverse_foreign_keys entity_map, fragment['entities'] model end
Private Instance Methods
add_entities(model, entity_fragment)
click to toggle source
Reconstruct entities and add them to the given model
# File lib/nose/serialize.rb, line 519 def add_entities(model, entity_fragment) # Recreate all the entities entity_map = {} entity_fragment.each do |entity_hash| entity_map[entity_hash['name']] = Entity.new entity_hash['name'] end # Populate the entities and add them to the workload entities = EntityRepresenter.represent([]) entities = entities.from_hash entity_fragment, user_options: { entity_map: entity_map } entities.each { |entity| model.add_entity entity } entity_map end
add_reverse_foreign_keys(entity_map, entity_fragment)
click to toggle source
Add all the reverse foreign keys @return [void]
# File lib/nose/serialize.rb, line 537 def add_reverse_foreign_keys(entity_map, entity_fragment) entity_fragment.each do |entity| entity['fields'].each do |field_hash| if field_hash['type'] == 'foreign_key' field = entity_map[entity['name']] \ .foreign_keys[field_hash['name']] field.reverse = field.entity.foreign_keys[field_hash['reverse']] field.instance_variable_set :@relationship, field_hash['relationship'].to_sym end field.freeze end end end