Class: Raven::Backtrace

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

Overview

Front end to parsing the backtrace for each notice

Defined Under Namespace

Classes: Line

Constant Summary collapse

APP_DIRS_PATTERN =
/(bin|exe|app|config|lib|test)/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lines) ⇒ Backtrace

Returns a new instance of Backtrace


109
110
111
# File 'lib/raven/backtrace.rb', line 109

def initialize(lines)
  self.lines = lines
end

Instance Attribute Details

#linesObject

holder for an Array of Backtrace::Line instances


90
91
92
# File 'lib/raven/backtrace.rb', line 90

def lines
  @lines
end

Class Method Details

.parse(backtrace, opts = {}) ⇒ Object


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/raven/backtrace.rb', line 92

def self.parse(backtrace, opts = {})
  ruby_lines = backtrace.is_a?(Array) ? backtrace : backtrace.split(/\n\s*/)

  filters = opts[:filters] || []
  filtered_lines = ruby_lines.to_a.map do |line|
    filters.reduce(line) do |nested_line, proc|
      proc.call(nested_line)
    end
  end.compact

  lines = filtered_lines.map do |unparsed_line|
    Line.parse(unparsed_line)
  end

  new(lines)
end

Instance Method Details

#==(other) ⇒ Object


125
126
127
128
129
130
131
# File 'lib/raven/backtrace.rb', line 125

def ==(other)
  if other.respond_to?(:lines)
    lines == other.lines
  else
    false
  end
end

#inspectObject


113
114
115
# File 'lib/raven/backtrace.rb', line 113

def inspect
  "<Backtrace: " + lines.map(&:inspect).join(", ") + ">"
end

#to_sObject


117
118
119
120
121
122
123
# File 'lib/raven/backtrace.rb', line 117

def to_s
  content = []
  lines.each do |line|
    content << line
  end
  content.join("\n")
end