Class: DaemonKit::ErrorHandlers::Hoptoad::Backtrace::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/daemon_kit/error_handlers/hoptoad.rb

Overview

Handles backtrace parsing line by line (Graciously borrowed from github.com/thoughtbot/hoptoad_notifier)

Constant Summary collapse

INPUT_FORMAT =
%r{^([^:]+):(\d+)(?::in `([^']+)')?$}.freeze

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.



35
36
37
38
39
# File 'lib/daemon_kit/error_handlers/hoptoad.rb', line 35

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

Instance Attribute Details

#fileObject

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



19
20
21
# File 'lib/daemon_kit/error_handlers/hoptoad.rb', line 19

def file
  @file
end

#methodObject

The method of the line (such as index)



25
26
27
# File 'lib/daemon_kit/error_handlers/hoptoad.rb', line 25

def method
  @method
end

#numberObject

The line number portion of the line



22
23
24
# File 'lib/daemon_kit/error_handlers/hoptoad.rb', line 22

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



30
31
32
33
# File 'lib/daemon_kit/error_handlers/hoptoad.rb', line 30

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



46
47
48
# File 'lib/daemon_kit/error_handlers/hoptoad.rb', line 46

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

#inspectObject



50
51
52
# File 'lib/daemon_kit/error_handlers/hoptoad.rb', line 50

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

#to_sObject

Reconstructs the line in a readable fashion



42
43
44
# File 'lib/daemon_kit/error_handlers/hoptoad.rb', line 42

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

#to_xmlObject



54
55
56
57
# File 'lib/daemon_kit/error_handlers/hoptoad.rb', line 54

def to_xml
  data = [ method, file, number ].map { |s| URI.escape( s || 'unknown', %q{"'<>&} ) }
  %q{<line method="%s" file="%s" number="%s" />} % data
end