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

  • parents: List of items whose children we will detach.

  • parent_prop: Name of the parent property on the children.

  • parent_key: Name that Seiso expects for the parent key.

  • child_prop: Name of the child property on the items.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/seiso/import_master/importers/base_importer.rb', line 17

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