Class: CallMap::Formatters::TextTree

Inherits:
Object
  • Object
show all
Defined in:
lib/call_map/formatters/text_tree.rb

Overview

Renders a CallNode tree as a text tree using box-drawing characters, suitable for pasting into Notion or pull requests.

OrdersController#destroy
├─ before_action set_order
  └─ Order.find
└─ OrderDeleteService.execute
 └─ OrderDeleteService#execute

With include_comments: true, a resolved node's leading comment is appended as an inline annotation (opt-in — comments are reading aid, not call-graph structure):

└─ OrderDeleteService#execute  # Destroys the order.

Constant Summary collapse

MAX_COMMENT_LENGTH =

Only the first comment line is shown, truncated to keep the tree scannable.

60

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(include_comments: false) ⇒ TextTree

Returns a new instance of TextTree.



30
31
32
# File 'lib/call_map/formatters/text_tree.rb', line 30

def initialize(include_comments: false)
  @include_comments = include_comments
end

Class Method Details

.format(root, include_comments: false) ⇒ String

Parameters:

  • root (CallNode)
  • include_comments (Boolean) (defaults to: false)

    append leading comments to resolved nodes

Returns:

  • (String)


26
27
28
# File 'lib/call_map/formatters/text_tree.rb', line 26

def self.format(root, include_comments: false)
  new(include_comments: include_comments).format(root)
end

Instance Method Details

#format(root) ⇒ Object



34
35
36
37
38
# File 'lib/call_map/formatters/text_tree.rb', line 34

def format(root)
  lines = [node_label(root)]
  append_children(lines, root.children, "")
  "#{lines.join("\n")}\n"
end