Class: CrashLog::Backtrace::Line
- Inherits:
-
Object
- Object
- CrashLog::Backtrace::Line
- Defined in:
- lib/crash_log/backtrace/line.rb
Constant Summary collapse
- INPUT_FORMAT =
Backtrace line parsing regexp (optionnally allowing leading X: for windows support)
%r{^((?:[a-zA-Z]:)?[^:]+):(\d+)(?::in `([^']+)')?$}
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
The file portion of the line (such as app/models/user.rb).
-
#method ⇒ Object
readonly
The method of the line (such as index).
-
#number ⇒ Object
readonly
The line number portion of the line.
-
#original_file ⇒ Object
readonly
The file portion of the line (such as app/models/user.rb).
Class Method Summary collapse
-
.parse(unparsed_line) ⇒ Line
Parses a single line of a given backtrace backtrace.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #apply_filter(filter) ⇒ Object
- #as_json ⇒ Object
- #context_line ⇒ Object (also: #line_context)
- #context_lines ⇒ Object
-
#initialize(file, number, method) ⇒ Line
constructor
A new instance of Line.
- #inspect ⇒ Object
- #marked_for_deletion? ⇒ Boolean
- #post_context ⇒ Object
- #pre_context ⇒ Object
- #to_hash ⇒ Object
-
#to_s ⇒ Object
Reconstructs the line in a readable fashion.
Constructor Details
#initialize(file, number, method) ⇒ Line
Returns a new instance of Line.
27 28 29 30 31 32 |
# File 'lib/crash_log/backtrace/line.rb', line 27 def initialize(file, number, method) self.file = file self.original_file = file self.number = number.to_i self.method = method end |
Instance Attribute Details
#file ⇒ Object
The file portion of the line (such as app/models/user.rb)
10 11 12 |
# File 'lib/crash_log/backtrace/line.rb', line 10 def file @file end |
#method ⇒ Object
The method of the line (such as index)
16 17 18 |
# File 'lib/crash_log/backtrace/line.rb', line 16 def method @method end |
#number ⇒ Object
The line number portion of the line
13 14 15 |
# File 'lib/crash_log/backtrace/line.rb', line 13 def number @number end |
#original_file ⇒ Object
The file portion of the line (such as app/models/user.rb)
10 11 12 |
# File 'lib/crash_log/backtrace/line.rb', line 10 def original_file @original_file end |
Class Method Details
.parse(unparsed_line) ⇒ Line
Parses a single line of a given backtrace backtrace.
22 23 24 25 |
# File 'lib/crash_log/backtrace/line.rb', line 22 def self.parse(unparsed_line) _, file, number, method = unparsed_line.match(INPUT_FORMAT).to_a new(file, number, method) end |
Instance Method Details
#==(other) ⇒ Object
39 40 41 |
# File 'lib/crash_log/backtrace/line.rb', line 39 def ==(other) to_s == other.to_s end |
#apply_filter(filter) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/crash_log/backtrace/line.rb', line 43 def apply_filter(filter) result = filter.call(file) if result.nil? # Filter returned nil, discard this line @_mark_for_deletion = true else # Filter manipulated parsed file name only self.file = result end end |
#as_json ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/crash_log/backtrace/line.rb', line 84 def as_json {}.tap do |hash| hash[:number] = number hash[:method] = method hash[:file] = file if context_lines hash[:context_line] = context_line hash[:pre_context] = pre_context hash[:post_context] = post_context end end end |
#context_line ⇒ Object Also known as: line_context
54 55 56 |
# File 'lib/crash_log/backtrace/line.rb', line 54 def context_line Backtrace::LineCache::getline(original_file, number) end |
#context_lines ⇒ Object
72 73 74 |
# File 'lib/crash_log/backtrace/line.rb', line 72 def context_lines CrashLog.configuration.context_lines end |
#inspect ⇒ Object
76 77 78 |
# File 'lib/crash_log/backtrace/line.rb', line 76 def inspect "<Line:#{to_s}>" end |
#marked_for_deletion? ⇒ Boolean
98 99 100 |
# File 'lib/crash_log/backtrace/line.rb', line 98 def marked_for_deletion? @_mark_for_deletion == true end |
#post_context ⇒ Object
66 67 68 69 70 |
# File 'lib/crash_log/backtrace/line.rb', line 66 def post_context (number+1..number+context_lines).map {|i| Backtrace::LineCache.getline(original_file, i) }.select { |line| line } end |
#pre_context ⇒ Object
60 61 62 63 64 |
# File 'lib/crash_log/backtrace/line.rb', line 60 def pre_context (number-context_lines..number-1).map {|i| Backtrace::LineCache.getline(original_file, i) }.select { |line| line } end |
#to_hash ⇒ Object
80 81 82 |
# File 'lib/crash_log/backtrace/line.rb', line 80 def to_hash as_json end |
#to_s ⇒ Object
Reconstructs the line in a readable fashion
35 36 37 |
# File 'lib/crash_log/backtrace/line.rb', line 35 def to_s "#{file}:#{number}:in `#{method}'" end |