1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Slightly refactor REPL initialization

This commit is contained in:
Ryan Fitzgerald 2012-12-23 00:08:40 -08:00
parent 2cfbd49f52
commit 3c6ffaf69c
5 changed files with 30 additions and 17 deletions

View file

@ -137,7 +137,8 @@ class Pry
end
alias current_context current_binding # support previous API
# Push a binding for the given object onto the stack.
# Push a binding for the given object onto the stack. If this instance is
# currently stopped, mark it as usable again.
def push_binding(object)
@stopped = false
binding_stack << Pry.binding_for(object)
@ -304,7 +305,7 @@ class Pry
complete_expr = Pry::Code.complete_expression?(@eval_string)
rescue SyntaxError => e
output.puts "SyntaxError: #{e.message.sub(/.*syntax error, */m, '')}"
@eval_string = ""
reset_line
end
if complete_expr
@ -332,10 +333,20 @@ class Pry
throw(:breakout) if current_binding.nil?
end
# @deprecated - Please use Pry::REPL.start(:pry => pry, :target => target) instead.
def repl(target=binding_stack.last)
@@repl_warning ||= (warn "(deprecation) Pry#repl has been replaced by Pry::REPL.start(:pry => pry)"; true)
Pry::REPL.start(:pry => self, :target => target)
# @deprecated Use `Pry::REPL.new(pry, :target => target).start` instead.
def repl(target = nil)
@@repl_warning ||= (warn Pry::Helpers::CommandHelpers.unindent(<<-S); true)
DEPRECATION: Pry#repl is deprecated. Instead, use
Pry::REPL.new(pry, :target => target).start
where pry is the Pry instance you called #repl on and target is the
optional target parameter of #repl.
Call stack:
#{caller.join("\n" + (' ' * 8))}
S
Pry::REPL.new(self, :target => target).start
end
def evaluate_ruby(code)
@ -551,7 +562,7 @@ class Pry
Pry.critical_section do
# If input buffer is empty then use normal prompt
if @eval_string.empty?
if eval_string.empty?
generate_prompt(Array(prompt).first, c)
# Otherwise use the wait prompt (indicating multi-line expression)

View file

@ -8,15 +8,16 @@ class Pry
def_delegators :pry, :input, :output, :input_stack
def self.start(options)
new(options).start
new(Pry.new(options)).start
end
def initialize(options)
@pry = options[:pry] || Pry.new(options)
if options[:pry] && options[:target]
def initialize(pry, options = {})
@pry = pry
@indent = Pry::Indent.new
if options[:target]
@pry.push_binding options[:target]
end
@indent = Pry::Indent.new
end
def start

View file

@ -23,7 +23,7 @@ class ReplTester
def initialize
@pry = Pry.new
@repl = Pry::REPL.new(:pry => @pry)
@repl = Pry::REPL.new(@pry)
@fiber = Fiber.new do
@repl.start

View file

@ -30,9 +30,10 @@ describe "Pry#input_stack" do
it 'input objects should be popped off stack as they are used up' do
stack = [StringIO.new(":cloister\n"), StringIO.new(":baron\n")]
repl = Pry::REPL.new :input => StringIO.new(":alex\n"),
pry = Pry.new :input => StringIO.new(":alex\n"),
:output => @str_output,
:input_stack => stack
repl = Pry::REPL.new pry
stack.size.should == 2
repl.send(:retrieve_line).should == ":alex\n"
stack.size.should == 2

View file

@ -15,7 +15,7 @@ describe "The REPL" do
it "shouldn't break if we start a nested session" do
ReplTester.start do |t|
t.in 'Pry::REPL.start(:pry => _pry_, :target => 10)'
t.in 'Pry::REPL.new(_pry_, :target => 10).start'
t.out ''
t.prompt /10.*> $/