Module: Trailblazer::Developer::Trace::ParentMap

Defined in:
lib/trailblazer/developer/trace/parent_map.rb

Overview

Map each Node instance to its parent Node.

Class Method Summary collapse

Class Method Details

.build(trace_nodes) ⇒ Object

DISCUSS: where does this belong?



6
7
8
9
10
11
12
13
14
# File 'lib/trailblazer/developer/trace/parent_map.rb', line 6

def self.build(trace_nodes)
  levels = {}
  trace_nodes.collect do |node|
    level = node.level
    levels[level] = node

    [node, levels[level - 1]]
  end.to_h
end

.path_for(parent_map, node) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/trailblazer/developer/trace/parent_map.rb', line 17

def self.path_for(parent_map, node)
  path = []

  while parent = parent_map[node] # DISCUSS: what if the graphs are cached and present, already?
    node_id = Activity::Introspect.Nodes(node.snapshot_before.activity, task: node.snapshot_before.task).id
    path << node_id

    node = parent
  end

  path.reverse
end