Class: Honeybadger::Backtrace Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Front end to parsing the backtrace for each notice.

Defined Under Namespace

Classes: Line

Constant Summary collapse

DEFAULT_LIMIT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

1000

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lines, limit = DEFAULT_LIMIT) ⇒ Backtrace

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Backtrace.



130
131
132
133
134
# File 'lib/honeybadger/backtrace.rb', line 130

def initialize(lines, limit = DEFAULT_LIMIT)
  self.lines = lines
  self.application_lines = lines.select(&:application?)
  self.limit = limit || DEFAULT_LIMIT
end

Instance Attribute Details

#application_linesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Holder for an Array of Backtrace::Line instances.



118
119
120
# File 'lib/honeybadger/backtrace.rb', line 118

def application_lines
  @application_lines
end

#linesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Holder for an Array of Backtrace::Line instances.



118
119
120
# File 'lib/honeybadger/backtrace.rb', line 118

def lines
  @lines
end

Class Method Details

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



120
121
122
123
124
125
126
127
128
# File 'lib/honeybadger/backtrace.rb', line 120

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

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

  new(lines, opts.fetch(:limit, DEFAULT_LIMIT))
end

Instance Method Details

#==(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



166
167
168
169
170
171
172
# File 'lib/honeybadger/backtrace.rb', line 166

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

#as_json(options = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

JSON support.

Returns JSON representation of backtrace.



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

def as_json(options = {})
  to_ary
end

#inspectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



162
163
164
# File 'lib/honeybadger/backtrace.rb', line 162

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

#to_aryObject Also known as: to_a

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert Backtrace to arry.

Returns array containing backtrace lines.



139
140
141
# File 'lib/honeybadger/backtrace.rb', line 139

def to_ary
  lines.take(limit.clamp(0..)).map { |l| {number: l.filtered_number, file: l.filtered_file, method: l.filtered_method, source: l.source} }
end

#to_json(*a) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates JSON.

Returns valid JSON representation of backtrace.



154
155
156
# File 'lib/honeybadger/backtrace.rb', line 154

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

#to_sObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



158
159
160
# File 'lib/honeybadger/backtrace.rb', line 158

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