Skip to content

Commit

Permalink
Merge pull request #18 from ConradIrwin/feature/kill-pry-rescue
Browse files Browse the repository at this point in the history
kill-pry-rescue (for guard, etc)
  • Loading branch information
ConradIrwin committed Dec 31, 2012
2 parents dcdc273 + 6a31294 commit fb61bb3
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
37 changes: 37 additions & 0 deletions bin/kill-pry-rescue
@@ -0,0 +1,37 @@
#!/usr/bin/env ruby

def find_pry_rescuers extra_id = ''
pattern = 'pry-rescue @.*' + extra_id
pids = nil
IO.popen ['pgrep', '-f', pattern] do |io|
pids = io.readlines.map &:to_i
end
pids
end

if %w(-h --help').include? ARGV[0]
warn %{
#$0 - Stops a pry-rescuer
By default gets all of them, but if you provide an arg, it can filter by the
directory name.
Uses SIGINT by default, unless you supply the -9 option.
Currently running pry-rescue pids: #{find_pry_rescuers.join ' '}}
exit 1
end

signal =
if ARGV.delete '-9'
:KILL
else
:INT
end

pids = find_pry_rescuers(ARGV.join ' ')
warn '(No processes found.)' if pids.size.zero?
pids.each do |pid|
warn "Killing #{pid} with SIG#{signal}."
Process.kill signal, pid
end
22 changes: 16 additions & 6 deletions lib/pry-rescue.rb
Expand Up @@ -48,12 +48,14 @@ def enter_exception_context(raised)
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)
with_program_name "#$PROGRAM_NAME [in pry-rescue @ #{Dir.pwd}]" do
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
end
ensure
@exception_context_depth -= 1
Expand Down Expand Up @@ -164,5 +166,13 @@ def pry_hooks(ex, raised)

hooks
end

def with_program_name name
before = $PROGRAM_NAME
$PROGRAM_NAME = name
yield
ensure
$PROGRAM_NAME = before
end
end
end
4 changes: 2 additions & 2 deletions pry-rescue.gemspec
@@ -1,14 +1,14 @@
Gem::Specification.new do |s|
s.name = 'pry-rescue'
s.version = '0.13'
s.version = '0.14'
s.summary = 'Open a pry session on any unhandled exceptions'
s.description = 'Allows you to wrap code in Pry::rescue{ } to open a pry session at any unhandled exceptions'
s.homepage = 'https://github.com/ConradIrwin/pry-rescue'
s.email = ['conrad.irwin@gmail.com', 'jrmair@gmail.com', 'chris@ill-logic.com']
s.authors = ['Conrad Irwin', 'banisterfiend', 'epitron']
s.files = `git ls-files`.split("\n")
s.require_paths = ['lib']
s.executables = ['rescue']
s.executables = s.files.grep(%r{^bin/}).map{|f| File.basename f}

s.add_dependency 'pry'
s.add_dependency 'interception', '>= 0.3'
Expand Down

0 comments on commit fb61bb3

Please sign in to comment.