Class: Raven::Backtrace::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/raven/backtrace.rb

Overview

Handles backtrace parsing line by line

Constant Summary collapse

INPUT_FORMAT =

regexp (optionnally allowing leading X: for windows support)

%r{^((?:[a-zA-Z]:)?[^:]+|<.*>):(\d+)(?::in `([^']+)')?$}.freeze
APP_DIRS_PATTERN =
/(bin|app|config|lib|test)/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, number, method) ⇒ Line

Returns a new instance of Line.



33
34
35
36
37
# File 'lib/raven/backtrace.rb', line 33

def initialize(file, number, method)
  self.file = file
  self.number = number.to_i
  self.method = method
end

Instance Attribute Details

#fileObject

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



17
18
19
# File 'lib/raven/backtrace.rb', line 17

def file
  @file
end

#methodObject

The method of the line (such as index)



23
24
25
# File 'lib/raven/backtrace.rb', line 23

def method
  @method
end

#numberObject

The line number portion of the line



20
21
22
# File 'lib/raven/backtrace.rb', line 20

def number
  @number
end

Class Method Details

.parse(unparsed_line) ⇒ Line

Parses a single line of a given backtrace

Parameters:

  • unparsed_line (String)

    The raw line from caller or some backtrace

Returns:

  • (Line)

    The parsed backtrace line



28
29
30
31
# File 'lib/raven/backtrace.rb', line 28

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



59
60
61
# File 'lib/raven/backtrace.rb', line 59

def ==(other)
  to_s == other.to_s
end

#in_appObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/raven/backtrace.rb', line 39

def in_app
  app_dirs = Raven.configuration.app_dirs_pattern || APP_DIRS_PATTERN
  @in_app_pattern ||= Regexp.new("^(#{project_root}/)?#{app_dirs}")

  if self.file =~ @in_app_pattern
    true
  else
    false
  end
end

#inspectObject



63
64
65
# File 'lib/raven/backtrace.rb', line 63

def inspect
  "<Line:#{to_s}>"
end

#project_rootObject



50
51
52
# File 'lib/raven/backtrace.rb', line 50

def project_root
  @project_root ||= Raven.configuration.project_root && Raven.configuration.project_root.to_s
end

#to_sObject

Reconstructs the line in a readable fashion



55
56
57
# File 'lib/raven/backtrace.rb', line 55

def to_s
  "#{file}:#{number}:in `#{method}'"
end