Skip to content

Commit

Permalink
added all_exceptions option to config, forcing catch of all exception…
Browse files Browse the repository at this point in the history
…s that arise, also added total number of frames into the prompt
  • Loading branch information
banister committed Nov 4, 2011
1 parent 18853ca commit 5dac978
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/pry_time/config.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module PryTime
class Config
attr_accessor :predicate_proc
attr_accessor :all_exceptions

def self.option_builder(option_name)
define_method(option_name) do
Expand Down
23 changes: 18 additions & 5 deletions lib/pry_time/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def exception_bindings
def pry_config
{
:prompt => Pry::DEFAULT_PROMPT.map do |p|
proc { |*args| "<Frame: #{binding_index}> #{p.call(*args)}" }
proc { |*args| "<Frame: #{binding_index}/#{exception_bindings.size - 1}> #{p.call(*args)}" }
end,

:commands => Pry::CommandSet.new do
Expand All @@ -49,19 +49,32 @@ class << obj; self; end.class_eval do
end

def should_capture_exception?
config.from_class.include?(exception_bindings.first.eval("self.class")) ||
config.all_exceptions ||
config.from_class.include?(exception_bindings.first.eval("self.class")) ||
config.from_method.include?(exception_bindings.first.eval("__method__")) ||
config.exception_type.any? { |v| v === current_exception } ||
exec_predicate_proc
end

def binding_index=(index)
@binding_index = index
pry_instance.binding_stack[-1] = exception_bindings[binding_index]
if index > exception_bindings.size - 1
pry_instance.output.puts "Warning: At top of stack, cannot go further!"
elsif index < 0
pry_instance.output.puts "Warning: At bottom of stack, cannot go further!"
else
@binding_index = index
pry_instance.binding_stack[-1] = exception_bindings[binding_index]
pry_instance.run_command "whereami"
end
end

def start_session
pry_instance.repl exception_bindings[binding_index]
PryTime.data[:in_session] = true
begin
pry_instance.repl exception_bindings[binding_index]
ensure
PryTime.data[:in_session] = false
end
end
end
end

0 comments on commit 5dac978

Please sign in to comment.