Class: PryRescue
- Inherits:
-
Object
- Object
- PryRescue
- Defined in:
- lib/pry-rescue.rb,
lib/pry-rescue/peek.rb,
lib/pry-rescue/rack.rb,
lib/pry-rescue/rails.rb,
lib/pry-rescue/rspec.rb
Overview
PryRescue provides the ability to open a Pry shell whenever an unhandled exception is raised in your code.
The main API is exposed via the Pry object, but here are a load of helpers that I didn’t want to pollute the Pry namespace with.
Defined Under Namespace
Class Method Summary collapse
-
.enter_exception_context(exception) ⇒ Object
Start a Pry session in the context of the exception.
-
.in_exception_context? ⇒ Boolean
Is the user currently inside pry rescue?.
-
.load(script) ⇒ Object
Load a script wrapped in Pry::rescue{ }.
-
.peek! ⇒ Object
Called when rescue –peek is used and the user hits <Ctrl+C> or sends whichever signal is configured.
- .peek_on_signal(signal) ⇒ Object
Class Method Details
.enter_exception_context(exception) ⇒ Object
Start a Pry session in the context of the exception.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/pry-rescue.rb', line 44 def enter_exception_context(exception) @exception_context_depth ||= 0 @exception_context_depth += 1 exception = exception.instance_variable_get(:@rescue_cause) if phantom_load_raise?(exception) bindings = exception.instance_variable_get(:@rescue_bindings) bindings = without_bindings_below_raise(bindings) bindings = without_duplicates(bindings) with_program_name "#$PROGRAM_NAME [in pry-rescue @ #{Dir.pwd}]" do if defined?(PryStackExplorer) pry :call_stack => bindings, :hooks => pry_hooks(exception), :initial_frame => initial_frame(bindings) else Pry.start bindings.first, :hooks => pry_hooks(exception) end end ensure @exception_context_depth -= 1 end |
.in_exception_context? ⇒ Boolean
Is the user currently inside pry rescue?
75 76 77 |
# File 'lib/pry-rescue.rb', line 75 def in_exception_context? @exception_context_depth && @exception_context_depth > 0 end |
.load(script) ⇒ Object
Load a script wrapped in Pry::rescue{ }
69 70 71 |
# File 'lib/pry-rescue.rb', line 69 def load(script) Pry::rescue{ Kernel.load script } end |
.peek! ⇒ Object
Called when rescue –peek is used and the user hits <Ctrl+C> or sends whichever signal is configured.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/pry-rescue/peek.rb', line 8 def self.peek!(*) puts 'Preparing to peek via pry!' unless ENV['NO_PEEK_STARTUP_MESSAGE'] require 'pry' unless binding.respond_to?(:of_caller) raise "pry-stack_explorer is not installed" end throw :raise_up, Interrupt if Pry === binding.of_caller(1).eval('self') binding.of_caller(1).pry # TODO pry :call_stack => binding.of_callers, :initial_frame => 1 end |
.peek_on_signal(signal) ⇒ Object
2 3 4 |
# File 'lib/pry-rescue/peek.rb', line 2 def self.peek_on_signal signal trap signal, &method(:peek!) end |