Class: Trailblazer::Developer::Trace::Debugger::Node

Inherits:
Struct
  • Object
show all
Defined in:
lib/trailblazer/developer/trace/debugger.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#activityObject

Returns the value of attribute activity



5
6
7
# File 'lib/trailblazer/developer/trace/debugger.rb', line 5

def activity
  @activity
end

#captured_inputObject

Returns the value of attribute captured_input



5
6
7
# File 'lib/trailblazer/developer/trace/debugger.rb', line 5

def captured_input
  @captured_input
end

#captured_nodeObject

Returns the value of attribute captured_node



5
6
7
# File 'lib/trailblazer/developer/trace/debugger.rb', line 5

def captured_node
  @captured_node
end

#captured_outputObject

Returns the value of attribute captured_output



5
6
7
# File 'lib/trailblazer/developer/trace/debugger.rb', line 5

def captured_output
  @captured_output
end

#compile_idObject

Returns the value of attribute compile_id



5
6
7
# File 'lib/trailblazer/developer/trace/debugger.rb', line 5

def compile_id
  @compile_id
end

#compile_pathObject

Returns the value of attribute compile_path



5
6
7
# File 'lib/trailblazer/developer/trace/debugger.rb', line 5

def compile_path
  @compile_path
end

#dataObject

Returns the value of attribute data



5
6
7
# File 'lib/trailblazer/developer/trace/debugger.rb', line 5

def data
  @data
end

#labelObject

Returns the value of attribute label



5
6
7
# File 'lib/trailblazer/developer/trace/debugger.rb', line 5

def label
  @label
end

#levelObject

Returns the value of attribute level



5
6
7
# File 'lib/trailblazer/developer/trace/debugger.rb', line 5

def level
  @level
end

#runtime_idObject

Returns the value of attribute runtime_id



5
6
7
# File 'lib/trailblazer/developer/trace/debugger.rb', line 5

def runtime_id
  @runtime_id
end

#runtime_pathObject

Returns the value of attribute runtime_path



5
6
7
# File 'lib/trailblazer/developer/trace/debugger.rb', line 5

def runtime_path
  @runtime_path
end

#taskObject

Returns the value of attribute task



5
6
7
# File 'lib/trailblazer/developer/trace/debugger.rb', line 5

def task
  @task
end

Class Method Details

.build(tree, enumerable_tree, node_options: {}, normalizer: Debugger::Normalizer::PIPELINES.last, **options_for_nodes) ⇒ Object

we always key options for specific nodes by Stack::Captured::Input, so we don’t confuse activities if they were called multiple times.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/trailblazer/developer/trace/debugger.rb', line 13

def self.build(tree, enumerable_tree, node_options: {}, normalizer: Debugger::Normalizer::PIPELINES.last, **options_for_nodes)
  parent_map = Trace::Tree::ParentMap.build(tree).to_h # DISCUSS: can we use {enumerable_tree} for {ParentMap}?


  container_activity = enumerable_tree[0].captured_input.activity # TODO: any other way to grab the container_activity? Maybe via {activity.container_activity}?

  # TODO: cache activity graph
  top_activity = enumerable_tree[0].captured_input.task

  task_maps_per_activity = {
    container_activity => {top_activity => {id: nil}} # exposes {Introspect::TaskMap}-compatible interface.
  }

  # DISCUSS: this might change if we introduce a new Node type for Trace.
  debugger_nodes = enumerable_tree[0..-1].collect do |node|
    activity      = node.captured_input.activity
    task          = node.captured_input.task
    # it's possible to pass per-node options, like {label: "Yo!"} via {:node_options[<captured_input>]}
    options       = node_options[node.captured_input] || {}



    task_map_for_activity = task_maps_per_activity[activity] || Activity::Introspect.TaskMap(activity)

    options_for_debugger_node, _ = normalizer.(
      {
        captured_node:          node,
        task:                   task,
        activity:               activity,
        parent_map:             parent_map,
        task_map_for_activity:  task_map_for_activity,
        **options
      },
      []
    )

    options_for_debugger_node = options_for_debugger_node.slice(*(options_for_debugger_node.keys - [:parent_map, :task_map_for_activity]))

    # these attributes are not changing with the presentation
    Debugger::Node.new(
      captured_node:  node,
      activity:       activity,
      task:           task,

      level: node.level,
      captured_input: node.captured_input,
      captured_output: node.captured_output,

      **options_for_debugger_node,
    ).freeze
  end
end

.build_for_stack(stack, **options_for_debugger_nodes) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/trailblazer/developer/trace/debugger.rb', line 66

def self.build_for_stack(stack, **options_for_debugger_nodes)
  tree, processed = Trace.Tree(stack.to_a)

  enumerable_tree = Trace::Tree.Enumerable(tree)

  Debugger::Node.build(
    tree,
    enumerable_tree,
    **options_for_debugger_nodes,
  )
end