Module: Eco::Data::Locations::NodeBase::Treeify
- Includes:
- Language::AuxiliarLogger
- Defined in:
- lib/eco/data/locations/node_base/treeify.rb
Overview
Note:
expects nodes to have these properties:
id,nameandparentIdparenttracked_level
Generic treeifier
Instance Attribute Summary
Attributes included from Language::AuxiliarLogger
Instance Method Summary collapse
-
#treeify(nodes, skipped: [], unlinked_trees: []) {|NodeBase| ... } ⇒ Array<Hash>
A hierarchical tree of nested Hashes via
nodeskey.
Methods included from Language::AuxiliarLogger
Instance Method Details
#treeify(nodes, skipped: [], unlinked_trees: []) {|NodeBase| ... } ⇒ Array<Hash>
Note:
if block is no given, it auto-detects the serializer block.
Returns a hierarchical tree of nested Hashes via nodes key.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/eco/data/locations/node_base/treeify.rb', line 15 def treeify(nodes, skipped: [], unlinked_trees: [], &block) return [] if nodes.empty? block ||= nodes.first.class.serializer done_ids = {} warns = [] parents = parents_hash(nodes) get_children(nil, parents, done_ids: done_ids, skipped: skipped, warns: warns, &block).tap do |tree| check_results( tree, nodes, parents, done_ids: done_ids, skipped: skipped, unlinked_trees: unlinked_trees, warns: warns, &block ) log(:warn) { warns.join("\n") } unless warns.empty? end end |