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,
lib/pry-rescue/source_location.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
Modules: SourceLocation Classes: RSpec, Rack, Railtie
Class Attribute Summary collapse
-
.any_exception_captured ⇒ Object
Returns the value of attribute any_exception_captured.
Class Method Summary collapse
-
.enter_exception_context(exception) ⇒ Object
Start a Pry session in the context of the exception.
- .exit_callbacks ⇒ Object
-
.in_exception_context? ⇒ Boolean
Is the user currently inside pry rescue?.
-
.load(script, ensure_repl = false) ⇒ Object
Load a script wrapped in Pry::rescue{ }.
- .load_rake(task) ⇒ Object
-
.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
- .run_exit_callbacks ⇒ Object
Class Attribute Details
.any_exception_captured ⇒ Object
Returns the value of attribute any_exception_captured.
42 43 44 |
# File 'lib/pry-rescue.rb', line 42 def any_exception_captured @any_exception_captured end |
Class Method Details
.enter_exception_context(exception) ⇒ Object
Start a Pry session in the context of the exception.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/pry-rescue.rb', line 46 def enter_exception_context(exception) @any_exception_captured = true @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 |
.exit_callbacks ⇒ Object
2 3 4 |
# File 'lib/pry-rescue/kernel_exit_hooks.rb', line 2 def exit_callbacks @exit_callbacks ||= [] end |
.in_exception_context? ⇒ Boolean
Is the user currently inside pry rescue?
93 94 95 |
# File 'lib/pry-rescue.rb', line 93 def in_exception_context? @exception_context_depth && @exception_context_depth > 0 end |
.load(script, ensure_repl = false) ⇒ Object
Load a script wrapped in Pry::rescue{ }
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/pry-rescue.rb', line 72 def load(script, ensure_repl = false) require File.('../pry-rescue/kernel_exit_hooks.rb', __FILE__) if ensure_repl Pry::rescue do begin TOPLEVEL_BINDING.eval File.read(script), script, 1 rescue SyntaxError => exception puts "#{exception}\n" end end end |
.load_rake(task) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/pry-rescue.rb', line 83 def load_rake(task) require 'rake' Pry::rescue do load "#{Dir.pwd}/Rakefile" Rake::Task[task].invoke end 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 |