class Binnacle::Trap::Backtrace::Line

Handles backtrace parsing line by line

Constants

GEMS_REGEXP
GEMS_RESULT
GEM_PATHS
INPUT_FORMAT

regexp (optionnally allowing leading X: for windows support)

Attributes

file[R]

The file portion of the line (such as app/models/user.rb)

method_name[R]

The method_name of the line (such as index)

number[R]

The line number portion of the line

Public Class Methods

new(file, number, method_name) click to toggle source
# File lib/binnacle/trap/backtrace.rb, line 50
def initialize(file, number, method_name)
  @file   = file
  @number = number
  @method_name = method_name
end
parse(unparsed_line) click to toggle source

Parses a single line of a given backtrace @param [String] unparsed_line The raw line from caller or some backtrace @return [Line] The parsed backtrace line

# File lib/binnacle/trap/backtrace.rb, line 32
def self.parse(unparsed_line)
  _, file, number, method_name = unparsed_line.match(INPUT_FORMAT).to_a

  # Remove Rails root from log lines
  file = defined?(Rails) ? file.gsub(Rails.root.to_s, '') : file

  if file
    # Clean those ERB lines, we don't need the internal autogenerated
    # ERB method, what we do need (line number in ERB file) is already there
    file = file.sub /(\.erb:\d+)\:in `__.*$/, "\\1"

    # Remove RubyGems root directories
    file = file.sub(GEMS_REGEXP, GEMS_RESULT)
  end

  new(file, number, method_name)
end

Public Instance Methods

==(other) click to toggle source
# File lib/binnacle/trap/backtrace.rb, line 61
def ==(other)
  to_s == other.to_s
end
empty?() click to toggle source
# File lib/binnacle/trap/backtrace.rb, line 69
def empty?
  file.nil? && number.nil? && method_name.nil?
end
inspect() click to toggle source
# File lib/binnacle/trap/backtrace.rb, line 65
def inspect
  "<Line:#{to_s}>"
end
to_s() click to toggle source

Reconstructs the line in a readable fashion

# File lib/binnacle/trap/backtrace.rb, line 57
def to_s
  "#{file}:#{number}:in `#{method_name}'"
end