Class: Naught::CallLocation
- Inherits:
-
Object
- Object
- Naught::CallLocation
- Defined in:
- lib/naught/call_location.rb
Overview
Represents a single method call in a null object's call trace
This class provides an interface similar to Thread::Backtrace::Location, capturing information about where a method was called on a null object.
Instance Attribute Summary collapse
-
#args ⇒ Array<Object>
readonly
Arguments passed to the method call.
-
#base_label ⇒ String?
readonly
The name of the method that made the call.
-
#label ⇒ String
readonly
The name of the method that was called.
-
#lineno ⇒ Integer
readonly
The line number where the call originated.
-
#path ⇒ String
(also: #absolute_path)
readonly
The absolute path to the file where the call originated.
Class Method Summary collapse
-
.from_caller(method_name, args, caller_string) ⇒ CallLocation
private
Create a CallLocation from a caller string.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Compare this CallLocation with another for equality.
-
#hash ⇒ Integer
Compute a hash value for this CallLocation.
-
#initialize(label:, args:, path:, lineno:, base_label: nil) ⇒ CallLocation
constructor
private
Initialize a new CallLocation.
-
#inspect ⇒ String
Returns a detailed inspect representation.
-
#to_s ⇒ String
Returns a human-readable string representation of the call.
Constructor Details
#initialize(label:, args:, path:, lineno:, base_label: nil) ⇒ CallLocation
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize a new CallLocation
77 78 79 80 81 82 83 |
# File 'lib/naught/call_location.rb', line 77 def initialize(label:, args:, path:, lineno:, base_label: nil) @label = label.to_s @args = args.dup.freeze @path = path @lineno = lineno @base_label = base_label end |
Instance Attribute Details
#args ⇒ Array<Object> (readonly)
Arguments passed to the method call
39 40 41 |
# File 'lib/naught/call_location.rb', line 39 def args @args end |
#base_label ⇒ String? (readonly)
The name of the method that made the call
67 68 69 |
# File 'lib/naught/call_location.rb', line 67 def base_label @base_label end |
#label ⇒ String (readonly)
The name of the method that was called
32 33 34 |
# File 'lib/naught/call_location.rb', line 32 def label @label end |
#lineno ⇒ Integer (readonly)
The line number where the call originated
60 61 62 |
# File 'lib/naught/call_location.rb', line 60 def lineno @lineno end |
#path ⇒ String (readonly) Also known as: absolute_path
The absolute path to the file where the call originated
46 47 48 |
# File 'lib/naught/call_location.rb', line 46 def path @path end |
Class Method Details
.from_caller(method_name, args, caller_string) ⇒ CallLocation
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a CallLocation from a caller string
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/naught/call_location.rb', line 16 def self.from_caller(method_name, args, caller_string) data = CallerInfo.parse(caller_string || "") new( label: method_name, args: args, path: data[:path] || "", lineno: data[:lineno], base_label: data[:base_label] ) end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Compare this CallLocation with another for equality
109 110 111 112 113 114 115 116 |
# File 'lib/naught/call_location.rb', line 109 def ==(other) other.is_a?(CallLocation) && label == other.label && args == other.args && path == other.path && lineno == other.lineno && base_label == other.base_label end |
#hash ⇒ Integer
Compute a hash value for this CallLocation
129 |
# File 'lib/naught/call_location.rb', line 129 def hash = [label, args, path, lineno, base_label].hash |
#inspect ⇒ String
Returns a detailed inspect representation
101 |
# File 'lib/naught/call_location.rb', line 101 def inspect = "#<#{self.class} #{self}>" |
#to_s ⇒ String
Returns a human-readable string representation of the call
90 91 92 93 94 |
# File 'lib/naught/call_location.rb', line 90 def to_s pretty_args = args.map(&:inspect).join(", ") location = base_label ? "#{path}:#{lineno}:in `#{base_label}'" : "#{path}:#{lineno}" "#{location} -> #{label}(#{pretty_args})" end |