Class: RubyMethodTracer::Formatters::TreeFormatter

Inherits:
BaseFormatter
  • Object
show all
Defined in:
lib/ruby_method_tracer/formatters/tree_formatter.rb

Overview

TreeFormatter generates hierarchical tree visualizations of method calls

Instance Method Summary collapse

Methods inherited from BaseFormatter

#colorize, #format_time

Instance Method Details

#format(call_tree, options = {}) ⇒ String

Format call tree into hierarchical string representation

rubocop:disable Metrics/AbcSize

Parameters:

  • call_tree (CallTree)

    The call tree to format

  • options (Hash) (defaults to: {})

    Formatting options

Options Hash (options):

  • :show_errors (Boolean) — default: true

    Include error information

  • :colorize (Boolean) — default: true

    Apply colors to output

Returns:

  • (String)

    Formatted tree visualization



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ruby_method_tracer/formatters/tree_formatter.rb', line 17

def format(call_tree, options = {})
  opts = default_options.merge(options)
  root_calls = call_tree.call_hierarchy

  return "No method calls recorded.\n" if root_calls.empty?

  output = []
  output << header
  output << separator

  root_calls.each_with_index do |call, index|
    is_last_root = index == root_calls.size - 1
    output << format_call_node(call, "", is_last_root, opts)
    output << "" unless is_last_root # Blank line between root calls
  end

  output << separator
  output << format_statistics(call_tree.statistics, opts)

  output.join("\n")
end