Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove pryception, it's now the pry-capture gem

  • Loading branch information...
commit 766f89a7c9f4f8abd98ee9c9cc1a683d4bf3a19b 1 parent 305245c
@ConradIrwin authored
Showing with 0 additions and 107 deletions.
  1. +0 −66 lib/pryception.rb
  2. +0 −41 pryly.rb
View
66 lib/pryception.rb
@@ -1,66 +0,0 @@
-require 'rubygems'
-require 'interception'
-require 'pry'
-
-begin
- require 'pry-stack_explorer'
-rescue LoadError
-end
-
-module Interception
-
- class << self
-
- # Intercept all exceptions that arise in the block and start a Pry session
- # at the fail site.
- def prycept(&block)
- raised = []
-
- Interception.listen(block) do |exception, binding|
- if defined?(PryStackExplorer)
- raised << [exception, binding.callers]
- else
- raised << [exception, Array(binding)]
- end
- end
-
- ensure
- if raised.any?
- exception, bindings = raised.last
- enter_exception_context(exception, bindings)
- end
- end
-
- private
-
- # Sanitize the call stack.
- # @param [Array<Binding>] bindings The call stack.
- def prune_call_stack!(bindings)
- bindings.delete_if { |b| b.eval("self") == self || b.eval("__method__") == :prycept }
- end
-
- # Start a Pry session in the context of the exception.
- # @param [Exception] exception The exception.
- # @param [Array<Binding>] bindings The call stack.
- def enter_exception_context(exception, bindings)
- inject_local("_ex_", exception, bindings.first)
- inject_local("_raised_", [exception, bindings.first], bindings.first)
-
- prune_call_stack!(bindings)
- if defined?(PryStackExplorer)
- pry :call_stack => bindings
- else
- bindings.first.pry
- end
- end
-
- # Inject a local variable into a binding.
- def inject_local(var, object, binding)
- Thread.current[:__intercept_var__] = object
- binding.eval("#{var} = Thread.current[:__intercept_var__]")
- ensure
- Thread.current[:__intercept_var__] = nil
- end
- end
-end
-
View
41 pryly.rb
@@ -1,41 +0,0 @@
-require 'rubygems'
-require 'interception'
-require 'pry'
-require 'pry-stack_explorer'
-def pryly(&block)
- raised = []
-
- Interception.listen(block) do |exception, binding|
- raised << [exception, binding.callers]
- end
-
-ensure
- if raised.last
- e, bindings = raised.last
- $foo = e
- $bar = raised
- bindings.first.eval("_ex_ = $foo")
- bindings.first.eval("_raised_ = $bar")
- bindings = bindings.drop_while { |b| b.eval("self") == Interception || b.eval("__method__") == :pryly }
- pry :call_stack => bindings
- end
-end
-
-pryly do
-
- def a
- begin
- begin
- raise "foo"
-
- rescue => e
- raise "bar"
- end
-
- rescue => e
- 1 / 0
-
- end
- end
- a
-end
Please sign in to comment.
Something went wrong with that request. Please try again.