Module: Trailblazer::Developer::Trace::Present

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

Class Method Summary collapse

Class Method Details

.call(stack, render_method: method(:render), node_options: {}, **options) ⇒ Object

Entry point for rendering a Stack as a “tree branch” the way we do it in #wtf?.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/trailblazer/developer/trace/present.rb', line 24

def call(stack, render_method: method(:render), node_options: {}, **options)
  # The top activity doesn't have an ID, hence we need to compute a default label.
  # TODO: maybe we should deep-merge here.
  captured_input_for_top_activity = stack.to_a[0]

  top_activity_options = {
    # we can pass particular label "hints".
    captured_input_for_top_activity => {
      # label: %{#{captured_input_for_top_activity.task.superclass} (anonymous)},
      label: captured_input_for_top_activity.task.inspect,
    },
  }

  node_options = top_activity_options.merge(node_options)

  debugger_nodes = Debugger::Node.build_for_stack(stack, node_options: node_options, **options) # currently, we agree on using a Debugger::Node list as the presentation data structure.

  return render_method.(debugger_nodes, **options)
end

.default_renderer(debugger_node:) ⇒ Object



9
10
11
# File 'lib/trailblazer/developer/trace/present.rb', line 9

def default_renderer(debugger_node:, **) # DISCUSS: for compatibility, should we pass {:task_node} here, too?
  [debugger_node.level, debugger_node.label]
end

.render(debugger_nodes, renderer: method(:default_renderer), **options_for_renderer) ⇒ Object

Returns the console output string.



15
16
17
18
19
20
21
# File 'lib/trailblazer/developer/trace/present.rb', line 15

def render(debugger_nodes, renderer: method(:default_renderer), **options_for_renderer)
  nodes = debugger_nodes.collect do |debugger_node|
    renderer.(debugger_node: debugger_node, tree: debugger_nodes, **options_for_renderer)
  end

  Hirb::Console.format_output(nodes, class: :tree, type: :directory, multi_line_nodes: true)
end