Skip to content

Commit

Permalink
Safer monkey-patching of Pry.start/.teardown
Browse files Browse the repository at this point in the history
Allows other plugins to do the same without triggering a
SystemStackError.
  • Loading branch information
Benjamin R. Haskell committed Oct 25, 2012
1 parent 1f7321a commit 3795bc0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
10 changes: 6 additions & 4 deletions lib/pry-nav/pry_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
require 'pry-nav/tracer'

class << Pry
alias_method :start_existing, :start
alias_method :start_without_pry_nav, :start

def start(target = TOPLEVEL_BINDING, options = {})
def start_with_pry_nav(target = TOPLEVEL_BINDING, options = {})
old_options = options.reject { |k, _| k == :pry_remote }

if target.is_a?(Binding) && PryNav.check_file_context(target)
# Wrap the tracer around the usual Pry.start
PryNav::Tracer.new(options).run do
start_existing(target, old_options)
start_without_pry_nav(target, old_options)
end
else
# No need for the tracer unless we have a file context to step through
start_existing(target, old_options)
start_without_pry_nav(target, old_options)
end
end

alias_method :start, :start_with_pry_nav
end
7 changes: 4 additions & 3 deletions lib/pry-nav/pry_remote_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ def run
end

# Override to reset our saved global current server session.
alias_method :teardown_existing, :teardown
def teardown
teardown_existing
alias_method :teardown_without_pry_nav, :teardown
def teardown_with_pry_nav
teardown_without_pry_nav
PryNav.current_remote_server = nil
end
alias_method :teardown, :teardown_with_pry_nav
end
end

Expand Down

0 comments on commit 3795bc0

Please sign in to comment.