Class: CallMap::CallNode

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

Overview

A node in the call tree. Holds the definition (if resolved), the original method call, and child nodes representing calls made from within this method.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition: nil, method_call: nil, children: [], circular: false) ⇒ CallNode

Returns a new instance of CallNode.

Parameters:

  • definition (Definition, nil) (defaults to: nil)

    resolved definition, nil for unresolved leaves

  • method_call (MethodCall, nil) (defaults to: nil)

    the call site that led here (nil for the root)

  • children (Array<CallNode>) (defaults to: [])
  • circular (Boolean) (defaults to: false)

    true when this node revisits a definition already on the current path



11
12
13
14
15
16
# File 'lib/call_map/call_node.rb', line 11

def initialize(definition: nil, method_call: nil, children: [], circular: false)
  @definition = definition
  @method_call = method_call
  @children = children
  @circular = circular
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



18
19
20
# File 'lib/call_map/call_node.rb', line 18

def children
  @children
end

#definitionObject (readonly)

Returns the value of attribute definition.



18
19
20
# File 'lib/call_map/call_node.rb', line 18

def definition
  @definition
end

#method_callObject (readonly)

Returns the value of attribute method_call.



18
19
20
# File 'lib/call_map/call_node.rb', line 18

def method_call
  @method_call
end

Instance Method Details

#circular?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/call_map/call_node.rb', line 24

def circular?
  @circular
end

#labelObject

Human-readable label for this node. A callback-originated node keeps its callback label (e.g. "before_action set_order") even when resolved, so tree output can distinguish it from a plain call. An unresolved call that points outside the indexed app code is marked as a framework leaf.



32
33
34
35
36
37
38
# File 'lib/call_map/call_node.rb', line 32

def label
  base = base_label
  return "#{base} [circular]" if circular?
  return "#{base} [framework]" if !resolved? && method_call&.framework_leaf?

  base
end

#resolved?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/call_map/call_node.rb', line 20

def resolved?
  !definition.nil?
end