2014-03-17 06:27:43 -04:00
|
|
|
#
|
|
|
|
# {Pry::LastException} is a proxy class who wraps an Exception object for
|
|
|
|
# {Pry#last_exception}. it extends the exception object with methods that
|
|
|
|
# help pry commands be useful.
|
|
|
|
#
|
|
|
|
# the original exception object is not modified and method calls are forwarded
|
|
|
|
# to the wrapped exception object.
|
|
|
|
#
|
2014-03-09 20:28:12 -04:00
|
|
|
class Pry::LastException < BasicObject
|
|
|
|
attr_accessor :bt_index
|
|
|
|
|
|
|
|
def initialize(e)
|
|
|
|
@e = e
|
|
|
|
@bt_index = 0
|
|
|
|
@file, @line = bt_source_location_for(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
def method_missing(name, *args, &block)
|
|
|
|
if @e.respond_to?(name)
|
|
|
|
@e.public_send(name, *args, &block)
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-04 04:34:24 -05:00
|
|
|
def respond_to_missing?(name, include_all = false)
|
2017-05-27 13:40:19 -04:00
|
|
|
@e.respond_to?(name, include_all)
|
2014-03-09 20:28:12 -04:00
|
|
|
end
|
|
|
|
|
2014-03-17 06:27:43 -04:00
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
# returns the path to a file for the current backtrace. see {#bt_index}.
|
|
|
|
#
|
|
|
|
def file
|
|
|
|
@file
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# @return [Fixnum]
|
|
|
|
# returns the line for the current backtrace. see {#bt_index}.
|
|
|
|
#
|
|
|
|
def line
|
|
|
|
@line
|
|
|
|
end
|
|
|
|
|
|
|
|
# @return [Exception]
|
|
|
|
# returns the wrapped exception
|
|
|
|
#
|
2014-03-09 22:39:01 -04:00
|
|
|
def wrapped_exception
|
|
|
|
@e
|
2014-03-09 20:28:12 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def bt_source_location_for(index)
|
|
|
|
backtrace[index] =~ /(.*):(\d+)/
|
|
|
|
[$1, $2.to_i]
|
|
|
|
end
|
|
|
|
|
|
|
|
def inc_bt_index
|
|
|
|
@bt_index = (@bt_index + 1) % backtrace.size
|
|
|
|
end
|
|
|
|
end
|