module DeepCover::Reporter::Tree::Util
Utility functions to deal with trees
Public Instance Methods
deep_merge(trees)
click to toggle source
list_to_twig(items)
click to toggle source
path_to_partial_paths(path)
click to toggle source
'some/example/path' => %w[some example path]
# File lib/deep_cover/reporter/tree/util.rb, line 35 def path_to_partial_paths(path) path.to_s.split('/') end
paths_to_tree(paths)
click to toggle source
# File lib/deep_cover/reporter/tree/util.rb, line 25 def paths_to_tree(paths) twigs = paths.map do |path| partials = path_to_partial_paths(path) list_to_twig(partials) end tree = deep_merge(twigs) simplify(tree) end
populate(tree, dir = '') { |full_path, path, children| ... }
click to toggle source
{a: {b: {}}} => [ra, rb] where rb = yield('a/b', 'b', []) and ra = yield('a', 'a', [rb])
# File lib/deep_cover/reporter/tree/util.rb, line 75 def populate(tree, dir = '', &block) return to_enum(__method__, tree, dir) unless block_given? tree.map do |path, children_hash| full_path = [dir, path].join children = populate(children_hash, "#{full_path}/", &block) yield full_path, path, children end end
populate_from_map(tree:, map:, merge:) { |full_path, partial_path, data, child_results || []| ... }
click to toggle source
# File lib/deep_cover/reporter/tree/util.rb, line 10 def populate_from_map(tree:, map:, merge:) return to_enum(__method__, tree: tree, map: map, merge: merge) unless block_given? final_results, _final_data = populate(tree) do |full_path, partial_path, children| if children.empty? data = map.fetch(full_path) else child_results, child_data = children.transpose data = merge.call(child_data) end result = yield full_path, partial_path, data, child_results || [] [result, data] end.transpose final_results end
simplify(tree)
click to toggle source