Class: TraceCalls::MethodCall
- Inherits:
-
Object
- Object
- TraceCalls::MethodCall
- Defined in:
- lib/trace_calls/method_call.rb
Instance Attribute Summary collapse
-
#called_at_lineno ⇒ Object
readonly
Returns the value of attribute called_at_lineno.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#lineno ⇒ Object
readonly
Returns the value of attribute lineno.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
- #<<(method_call) ⇒ Object
- #eql?(other) ⇒ Boolean
- #fully_qualified_name ⇒ Object
- #hash ⇒ Object
-
#initialize(name, scope, file_path, lineno, parent, called_at_lineno) ⇒ MethodCall
constructor
A new instance of MethodCall.
- #is_leaf? ⇒ Boolean
- #is_root? ⇒ Boolean
- #leaves ⇒ Object
- #qualified_name ⇒ Object
-
#to_s(detailed: false) ⇒ Object
-root -child 1 +-child 2 -child 3 -child 1.
Constructor Details
#initialize(name, scope, file_path, lineno, parent, called_at_lineno) ⇒ MethodCall
Returns a new instance of MethodCall.
13 14 15 16 17 18 19 20 21 |
# File 'lib/trace_calls/method_call.rb', line 13 def initialize(name, scope, file_path, lineno, parent, called_at_lineno) @name = name @scope = scope @file_path = file_path @lineno = lineno @parent = parent ? parent : self @called_at_lineno = called_at_lineno @children = [] end |
Instance Attribute Details
#called_at_lineno ⇒ Object (readonly)
Returns the value of attribute called_at_lineno.
5 6 7 |
# File 'lib/trace_calls/method_call.rb', line 5 def called_at_lineno @called_at_lineno end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
5 6 7 |
# File 'lib/trace_calls/method_call.rb', line 5 def children @children end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
5 6 7 |
# File 'lib/trace_calls/method_call.rb', line 5 def file_path @file_path end |
#lineno ⇒ Object (readonly)
Returns the value of attribute lineno.
5 6 7 |
# File 'lib/trace_calls/method_call.rb', line 5 def lineno @lineno end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/trace_calls/method_call.rb', line 5 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
5 6 7 |
# File 'lib/trace_calls/method_call.rb', line 5 def parent @parent end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
5 6 7 |
# File 'lib/trace_calls/method_call.rb', line 5 def scope @scope end |
Instance Method Details
#<<(method_call) ⇒ Object
31 32 33 34 |
# File 'lib/trace_calls/method_call.rb', line 31 def <<(method_call) @children << method_call self end |
#eql?(other) ⇒ Boolean
73 74 75 |
# File 'lib/trace_calls/method_call.rb', line 73 def eql?(other) other.hash == hash end |
#fully_qualified_name ⇒ Object
61 62 63 |
# File 'lib/trace_calls/method_call.rb', line 61 def fully_qualified_name "#{file_path}:#{lineno}:#{@scope}::#{@name}" end |
#hash ⇒ Object
69 70 71 |
# File 'lib/trace_calls/method_call.rb', line 69 def hash "#{parent.fully_qualified_name}\##{called_at_lineno}>#{fully_qualified_name}".hash end |
#is_leaf? ⇒ Boolean
27 28 29 |
# File 'lib/trace_calls/method_call.rb', line 27 def is_leaf? @children.empty? end |
#is_root? ⇒ Boolean
23 24 25 |
# File 'lib/trace_calls/method_call.rb', line 23 def is_root? @parent == self end |
#leaves ⇒ Object
36 37 38 39 |
# File 'lib/trace_calls/method_call.rb', line 36 def leaves return [self] if is_leaf? @children.map(&:leaves).flatten end |
#qualified_name ⇒ Object
65 66 67 |
# File 'lib/trace_calls/method_call.rb', line 65 def qualified_name "#{@scope}::#{@name}" end |
#to_s(detailed: false) ⇒ Object
+-root
+-child 1
+-child 2
\-child 3
\-child 1
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/trace_calls/method_call.rb', line 46 def to_s(detailed: false) method_name_to_get_node_name = (detailed ? :fully_qualified_name : :qualified_name) line = "" line << "+-" if is_root? line << "#{send(method_name_to_get_node_name)}" line << " called from #{parent.send(method_name_to_get_node_name)} at #{called_at_lineno}" unless is_root? unless children.empty? line << "\n" line << children[0..-2].map{ |child| treeify_child_line(child, detailed: detailed) }.join line << treeify_child_line(children.last, last_child: true, detailed: detailed) end line = line[0..-2] if line[-1] == "\n" line end |