Class: Honeybadger::Backtrace

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

Overview

Internal: Front end to parsing the backtrace for each notice

Defined Under Namespace

Classes: Line

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lines) ⇒ Backtrace

Returns a new instance of Backtrace.


125
126
127
128
# File 'lib/honeybadger/backtrace.rb', line 125

def initialize(lines)
  self.lines = lines
  self.application_lines = lines.select(&:application?)
end

Instance Attribute Details

#application_linesObject

Holder for an Array of Backtrace::Line instances.


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

def application_lines
  @application_lines
end

#linesObject

Holder for an Array of Backtrace::Line instances.


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

def lines
  @lines
end

Class Method Details

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


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

def self.parse(ruby_backtrace, opts = {})
  ruby_lines = split_multiline_backtrace(ruby_backtrace)

  lines = ruby_lines.collect do |unparsed_line|
    Line.parse(unparsed_line, opts)
  end.compact

  instance = new(lines)
end

Instance Method Details

#==(other) ⇒ Object


160
161
162
163
164
165
166
# File 'lib/honeybadger/backtrace.rb', line 160

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

#as_json(options = {}) ⇒ Object

JSON support.

Returns JSON representation of backtrace.


141
142
143
# File 'lib/honeybadger/backtrace.rb', line 141

def as_json(options = {})
  to_ary
end

#inspectObject


156
157
158
# File 'lib/honeybadger/backtrace.rb', line 156

def inspect
  "<Backtrace: " + lines.collect { |line| line.inspect }.join(", ") + ">"
end

#to_aryObject Also known as: to_a

Convert Backtrace to arry.

Returns array containing backtrace lines.


133
134
135
# File 'lib/honeybadger/backtrace.rb', line 133

def to_ary
  lines.take(1000).map { |l| { :number => l.filtered_number, :file => l.filtered_file, :method => l.filtered_method, :source => l.source } }
end

#to_json(*a) ⇒ Object

Creates JSON.

Returns valid JSON representation of backtrace.


148
149
150
# File 'lib/honeybadger/backtrace.rb', line 148

def to_json(*a)
  as_json.to_json(*a)
end

#to_sObject


152
153
154
# File 'lib/honeybadger/backtrace.rb', line 152

def to_s
  lines.map(&:to_s).join("\n")
end