Class: PryRescue

Inherits:
Object
  • Object
show all
Defined in:
lib/pry-rescue.rb,
lib/pry-rescue/rack.rb,
lib/pry-rescue/rails.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.

See Also:

  • {Pry{Pry::rescue}

Defined Under Namespace

Classes: Rack, Railtie

Class Method Summary collapse

Class Method Details

.enter_exception_context(raised) ⇒ Object

Start a Pry session in the context of the exception.

Parameters:

  • raised (Array<Exception, Array<Binding>>)

    The exceptions raised



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/pry-rescue.rb', line 30

def enter_exception_context(raised)
  @exception_context_depth ||= 0
  @exception_context_depth += 1

  raised = raised.map do |e, bs|
    [e, without_bindings_below_raise(bs)]
  end

  raised.pop if phantom_load_raise?(*raised.last)
  exception, bindings = raised.last
  bindings = without_duplicates(bindings)

  if defined?(PryStackExplorer)
    pry :call_stack => bindings,
        :hooks => pry_hooks(exception, raised),
        :initial_frame => initial_frame(bindings)
  else
    Pry.start bindings.first, :hooks => pry_hooks(exception, raised)
  end
ensure
  @exception_context_depth -= 1
end

.in_exception_context?Boolean

Is the user currently inside pry rescue?

Returns:

  • (Boolean)


61
62
63
# File 'lib/pry-rescue.rb', line 61

def in_exception_context?
  @exception_context_depth && @exception_context_depth > 0
end

.load(script) ⇒ Object

Load a script wrapped in Pry::rescue{ }

Parameters:

  • script (String)

    The name of the script



55
56
57
# File 'lib/pry-rescue.rb', line 55

def load(script)
  Pry::rescue{ Kernel.load script }
end