trailblazer-developer 0.0.28 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,86 +0,0 @@
1
- module Trailblazer
2
- module Developer
3
- module Trace
4
- # Datastructure representing a trace.
5
- class Tree
6
- # This could also be seen as {tree.to_a}.
7
- def self.Enumerable(node)
8
- Enumerable.nodes_for(node)
9
- end
10
-
11
- module Enumerable
12
- # @private
13
- def self.nodes_for(node)
14
- [node, *node.nodes.collect { |n| nodes_for(n) } ].flatten
15
- end
16
- end # Enumerable
17
-
18
- # Map each {Node} instance to its parent {Node}.
19
- module ParentMap
20
- def self.build(node)
21
- children_map = []
22
- node.nodes.each { |n| children_map += ParentMap.build(n) }#.flatten(1)
23
-
24
- node.nodes.collect { |n| [n, node] } + children_map
25
- end
26
-
27
- # @public
28
- def self.path_for(parent_map, node)
29
- path = []
30
-
31
- while parent = parent_map[node] # DISCUSS: what if the graphs are cached and present, already?
32
- node_id = Activity::Introspect.Nodes(node.captured_input.activity, task: node.captured_input.task).id
33
- path << node_id
34
-
35
- node = parent
36
- end
37
-
38
- path.reverse
39
- end
40
- end
41
-
42
- class Node < Struct.new(:level, :captured_input, :captured_output, :nodes)
43
- end
44
- end # Tree
45
-
46
-
47
- # Builds a tree graph from a linear stack.
48
- # Consists of {Tree::Node} structures.
49
- def self.Tree(stack_end, level: 0, parent: nil)
50
- processed = []
51
- nodes = []
52
-
53
- # for {captured_input} we're gonna build a {Node}!
54
- captured_input, remaining = stack_end[0], stack_end[1..-1]
55
-
56
- raise unless captured_input.is_a?(Captured::Input)
57
-
58
- while next_captured = remaining[0]
59
- if next_captured.is_a?(Captured::Input)
60
-
61
- bla, _processed = Tree(remaining, level: level+1)
62
- nodes += [bla]
63
- processed += _processed
64
-
65
-
66
- remaining = remaining - processed
67
-
68
- else # Captured::Output
69
-
70
- raise unless next_captured.is_a?(Captured::Output)
71
- raise if next_captured.activity != captured_input.activity
72
-
73
- node = Tree::Node.new(level, captured_input, next_captured, nodes)
74
-
75
- return node,
76
- [captured_input, *processed, next_captured] # what nodes did we process here?
77
-
78
- end
79
-
80
- end
81
-
82
-
83
- end # Tree
84
- end
85
- end # Developer
86
- end