Class: Seiso::ImportMaster::Importers::BaseImporter

Inherits:
Object
  • Object
show all
Defined in:
lib/seiso/import_master/importers/base_importer.rb

Overview

Author

Willie Wheeler ([email protected])

Copyright

Copyright © 2014-2015 Expedia, Inc.

License

Apache 2.0

Instance Method Summary collapse

Instance Method Details

#detach_children(parents, parent_prop, parent_key, child_prop) ⇒ Object

Enriches children with a link to the parent, detaches them from the parent, and returns all detached children.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/seiso/import_master/importers/base_importer.rb', line 12

def detach_children(parents, parent_prop, parent_key, child_prop)
  all_children = []
  parents.each do |p|
    children = p[child_prop]
    next if children.nil?
    children.each { |c| c[parent_prop] = p[parent_key] }
    all_children.push(*children)
    p.delete child_prop
  end
  all_children
end