Class: Honeybadger::Backtrace::Line
- Inherits:
-
Object
- Object
- Honeybadger::Backtrace::Line
- Defined in:
- lib/honeybadger/backtrace.rb
Overview
Internal: Handles backtrace parsing line by line
Constant Summary collapse
- INPUT_FORMAT =
Backtrace line regexp (optionally allowing leading X: for windows support)
%r{^((?:[a-zA-Z]:)?[^:]+):(\d+)(?::in `([^']+)')?$}.freeze
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
The file portion of the line (such as app/models/user.rb).
-
#filtered_file ⇒ Object
readonly
Filtered representations.
-
#filtered_method ⇒ Object
readonly
Filtered representations.
-
#filtered_number ⇒ Object
readonly
Filtered representations.
-
#method ⇒ Object
readonly
The method of the line (such as index).
-
#number ⇒ Object
readonly
The line number portion of the line.
Class Method Summary collapse
-
.parse(unparsed_line, opts = {}) ⇒ Object
Parses a single line of a given backtrace.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#application? ⇒ Boolean
Determines if this line is part of the application trace or not.
-
#initialize(file, number, method, filtered_file = file, filtered_number = number, filtered_method = method) ⇒ Line
constructor
A new instance of Line.
- #inspect ⇒ Object
-
#source(radius = 2) ⇒ Object
An excerpt from the source file, lazily loaded to preserve performance.
-
#to_s ⇒ Object
Reconstructs the line in a readable fashion.
Constructor Details
#initialize(file, number, method, filtered_file = file, filtered_number = number, filtered_method = method) ⇒ Line
Returns a new instance of Line.
48 49 50 51 52 53 54 55 56 |
# File 'lib/honeybadger/backtrace.rb', line 48 def initialize(file, number, method, filtered_file = file, filtered_number = number, filtered_method = method) self.filtered_file = filtered_file self.filtered_number = filtered_number self.filtered_method = filtered_method self.file = file self.number = number self.method = method end |
Instance Attribute Details
#file ⇒ Object
The file portion of the line (such as app/models/user.rb)
12 13 14 |
# File 'lib/honeybadger/backtrace.rb', line 12 def file @file end |
#filtered_file ⇒ Object
Filtered representations
21 22 23 |
# File 'lib/honeybadger/backtrace.rb', line 21 def filtered_file @filtered_file end |
#filtered_method ⇒ Object
Filtered representations
21 22 23 |
# File 'lib/honeybadger/backtrace.rb', line 21 def filtered_method @filtered_method end |
#filtered_number ⇒ Object
Filtered representations
21 22 23 |
# File 'lib/honeybadger/backtrace.rb', line 21 def filtered_number @filtered_number end |
#method ⇒ Object
The method of the line (such as index)
18 19 20 |
# File 'lib/honeybadger/backtrace.rb', line 18 def method @method end |
#number ⇒ Object
The line number portion of the line
15 16 17 |
# File 'lib/honeybadger/backtrace.rb', line 15 def number @number end |
Class Method Details
.parse(unparsed_line, opts = {}) ⇒ Object
Parses a single line of a given backtrace
unparsed_line - The raw line from caller
or some backtrace
Returns the parsed backtrace line
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/honeybadger/backtrace.rb', line 28 def self.parse(unparsed_line, opts = {}) filters = opts[:filters] || [] filtered_line = filters.reduce(unparsed_line) do |line, proc| # TODO: Break if nil if proc.arity == 2 proc.call(line, opts[:config]) else proc.call(line) end end if filtered_line _, file, number, method = unparsed_line.match(INPUT_FORMAT).to_a _, *filtered_args = filtered_line.match(INPUT_FORMAT).to_a new(file, number, method, *filtered_args) else nil end end |
Instance Method Details
#==(other) ⇒ Object
63 64 65 |
# File 'lib/honeybadger/backtrace.rb', line 63 def ==(other) to_s == other.to_s end |
#application? ⇒ Boolean
Determines if this line is part of the application trace or not.
72 73 74 |
# File 'lib/honeybadger/backtrace.rb', line 72 def application? (filtered_file =~ /^\[PROJECT_ROOT\]/i) && !(filtered_file =~ /^\[PROJECT_ROOT\]\/vendor/i) end |
#inspect ⇒ Object
67 68 69 |
# File 'lib/honeybadger/backtrace.rb', line 67 def inspect "<Line:#{to_s}>" end |
#source(radius = 2) ⇒ Object
An excerpt from the source file, lazily loaded to preserve performance.
78 79 80 |
# File 'lib/honeybadger/backtrace.rb', line 78 def source(radius = 2) @source ||= get_source(file, number, radius) end |
#to_s ⇒ Object
Reconstructs the line in a readable fashion.
59 60 61 |
# File 'lib/honeybadger/backtrace.rb', line 59 def to_s "#{filtered_file}:#{filtered_number}:in `#{filtered_method}'" end |