module Trailblazer::Developer::Wtf::Renderer

Constants

DEFAULT_COLOR_MAP
SIGNALS_MAP

Public Instance Methods

call(tree:, task_node:, position:) click to toggle source

tree: Array of Trace::TreeNodes::Node task_node - current Trace::TreeNodes::Node to render position - task_node's position in tree

# File lib/trailblazer/developer/wtf/renderer.rb, line 21
def call(tree:, task_node:, position:)
  value = value_for(tree, task_node, position)
  [task_node.level, value]
end
fmt(line, style) click to toggle source
# File lib/trailblazer/developer/wtf/renderer.rb, line 38
def fmt(line, style)
  if line.is_a? Method
    line = "#<Method: #<Class:>.#{line.name}>"
  end
  return line unless style
  String.send(style, line)
end
signal_of(task_node) click to toggle source
# File lib/trailblazer/developer/wtf/renderer.rb, line 46
def signal_of(task_node)
  entity_signal = task_node.output.data[:signal]
  entity_klass = entity_signal.is_a?(Class) ? entity_signal : entity_signal.class

  SIGNALS_MAP[entity_klass.name.to_sym]
end
value_for(tree, task_node, position) click to toggle source
# File lib/trailblazer/developer/wtf/renderer.rb, line 26
def value_for(tree, task_node, position)
  if task_node.output.nil? && tree[position.next].nil? # i.e. when exception raised
    return %{#{fmt(fmt(task_node.value, :red), :bold)}}
  end

  if task_node.output.nil? # i.e. on entry/exit point of activity
    return %{#{task_node.value}}
  end

  %{#{fmt(task_node.value, task_node.color_map[ signal_of(task_node) ])}}
end