Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to pass options to Pry.start #187

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 34 additions & 4 deletions lib/byebug/processors/pry_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,43 @@ class PryProcessor < CommandProcessor
def_delegators :@pry, :output
def_delegators Pry::Helpers::Text, :bold

def self.start
def self.start(target=nil, options={})
Byebug.start
Setting[:autolist] = false
Context.processor = self

# hack because byebug instantiates our class, so this lets us hang onto
# the binding until we have an instance to use it on
initializer = lambda do |*args, &b|
processor = new(*args, &b)
processor.enqueue_args([target, options])
processor
end
class << initializer
alias new call
end
Context.processor = initializer

Byebug.current_context.step_out(4, true)
end

def enqueue_args(args)
enqueued_args << args
end

private def enqueued_args
@enqueued_args ||= []
end

private def new_pry_args
if enqueued_args.any?
arg_binding, arg_options = enqueued_args.shift
arg_binding = frame._binding unless arg_binding.is_a? ::Binding
[arg_binding, arg_options]
else
[frame._binding, {}]
end
end

#
# Wrap a Pry REPL to catch navigational commands and act on them.
#
Expand Down Expand Up @@ -106,13 +136,13 @@ def n_hits(breakpoint)
# Resume an existing Pry REPL at the paused point.
#
def resume_pry
new_binding = frame._binding

run do
if defined?(@pry) && @pry
new_binding = frame._binding
@pry.repl(new_binding)
else
@pry = Pry.start_without_pry_byebug(new_binding)
@pry = Pry.start_without_pry_byebug(*new_pry_args)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pry-byebug/pry_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class << Pry

def start_with_pry_byebug(target = TOPLEVEL_BINDING, options = {})
if target.is_a?(Binding) && PryByebug.file_context?(target)
Byebug::PryProcessor.start unless ENV["DISABLE_PRY"]
Byebug::PryProcessor.start(target, options) unless ENV["DISABLE_PRY"]
else
# No need for the tracer unless we have a file context to step through
start_without_pry_byebug(target, options)
Expand Down