Class: Failbot::Backtrace::Frame

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

Overview

A parsed stack frame.

Constant Summary collapse

FRAME_FORMAT =
/
  \A
    \s*
    ([^:]+ | <.*>):         # abs_path
    (\d+)                   # line_number
    (?: :in \s `([^']+)')?  # method
  \z
/x

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(abs_path, file_name, line_number, method) ⇒ Frame

Returns a new instance of Frame.



80
81
82
83
84
85
# File 'lib/failbot/backtrace.rb', line 80

def initialize(abs_path, file_name, line_number, method)
  @abs_path = abs_path
  @file_name = file_name
  @line_number = line_number
  @method = method
end

Instance Attribute Details

#abs_pathObject (readonly)

Returns the value of attribute abs_path.



41
42
43
# File 'lib/failbot/backtrace.rb', line 41

def abs_path
  @abs_path
end

#file_nameObject (readonly)

Returns the value of attribute file_name.



41
42
43
# File 'lib/failbot/backtrace.rb', line 41

def file_name
  @file_name
end

#line_numberObject (readonly)

Returns the value of attribute line_number.



41
42
43
# File 'lib/failbot/backtrace.rb', line 41

def line_number
  @line_number
end

#methodObject (readonly)

Returns the value of attribute method.



41
42
43
# File 'lib/failbot/backtrace.rb', line 41

def method
  @method
end

Class Method Details

.parse(unparsed_line) ⇒ Object

Returns a Frame given backtrace component string or raises ParseError if it’s malformed.



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/failbot/backtrace.rb', line 45

def self.parse(unparsed_line)
  match = unparsed_line.match(FRAME_FORMAT)
  if match
    abs_path, line_number, method = match.captures

    file_name = extract_file_name(abs_path)

    new(abs_path, file_name, line_number, method)
  else
    raise ParseError, "unable to parse #{unparsed_line.inspect}"
  end
end

Instance Method Details

#to_sObject



87
88
89
# File 'lib/failbot/backtrace.rb', line 87

def to_s
  "#{file_name}:#{line_number}:in `#{method}'"
end