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

Remove various eval_str params (failing specs)

This commit is contained in:
Ryan Fitzgerald 2012-12-18 00:30:18 -08:00
parent 8a434a747d
commit ec1ad5fe4c

View file

@ -244,7 +244,7 @@ class Pry
@suppress_output = false @suppress_output = false
inject_sticky_locals! inject_sticky_locals!
case val = retrieve_line(@eval_string) case val = retrieve_line
when :control_c when :control_c
output.puts "" output.puts ""
@eval_string = "" @eval_string = ""
@ -252,7 +252,7 @@ class Pry
output.puts "" if output.tty? output.puts "" if output.tty?
Pry.config.control_d_handler.call(@eval_string, self) Pry.config.control_d_handler.call(@eval_string, self)
else else
ensure_correct_encoding!(@eval_string, val) ensure_correct_encoding!(val)
accept_line(val) accept_line(val)
end end
@ -262,7 +262,7 @@ class Pry
def accept_line(line) def accept_line(line)
begin begin
if !process_command_safely(line.lstrip, @eval_string) if !process_command_safely(line.lstrip)
@eval_string << "#{line.chomp}\n" unless line.empty? @eval_string << "#{line.chomp}\n" unless line.empty?
end end
rescue RescuableException => e rescue RescuableException => e
@ -338,25 +338,25 @@ class Pry
end end
end end
# Change the eval_string into the input encoding (Issue 284) # Change the @eval_string into the input encoding (Issue 284)
def ensure_correct_encoding!(eval_string, val) def ensure_correct_encoding!(val)
if eval_string.empty? && val.respond_to?(:encoding) && val.encoding != eval_string.encoding if @eval_string.empty? &&
eval_string.force_encoding(val.encoding) val.respond_to?(:encoding) &&
val.encoding != @eval_string.encoding
@eval_string.force_encoding(val.encoding)
end end
end end
private :ensure_correct_encoding! private :ensure_correct_encoding!
# Read and process a line of input -- check for ^D, determine which prompt to # Read and process a line of input -- check for ^D, determine which prompt to
# use, rewrite the indentation if `Pry.config.auto_indent` is enabled, and, # use, rewrite the indentation if `Pry.config.auto_indent` is enabled, and,
# if the line is a command, process it and alter the eval_string accordingly. # if the line is a command, process it and alter the @eval_string accordingly.
# This method should not need to be invoked directly.
# #
# @param [String] eval_string The cumulative lines of input.
# @return [String] The line received. # @return [String] The line received.
def retrieve_line(eval_string = '') def retrieve_line
@indent.reset if eval_string.empty? @indent.reset if @eval_string.empty?
current_prompt = select_prompt(eval_string) current_prompt = select_prompt
completion_proc = Pry.config.completer.build_completion_proc(current_binding, self, completion_proc = Pry.config.completer.build_completion_proc(current_binding, self,
instance_eval(&custom_completions)) instance_eval(&custom_completions))
@ -401,17 +401,16 @@ class Pry
end end
# If the given line is a valid command, process it in the context of the # If the given line is a valid command, process it in the context of the
# current `eval_string` and binding. # current `@eval_string` and binding.
# This method should not need to be invoked directly. # This method should not need to be invoked directly.
# @param [String] val The line to process. # @param [String] val The line to process.
# @param [String] eval_string The cumulative lines of input.
# @return [Boolean] `true` if `val` is a command, `false` otherwise # @return [Boolean] `true` if `val` is a command, `false` otherwise
def process_command(val, eval_string = '') def process_command(val)
val = val.chomp val = val.chomp
result = commands.process_line(val, result = commands.process_line(val,
:target => current_binding, :target => current_binding,
:output => output, :output => output,
:eval_string => eval_string, :eval_string => @eval_string,
:pry_instance => self :pry_instance => self
) )
@ -426,7 +425,7 @@ class Pry
# the command that was invoked was non-void (had a return value) and so we make # the command that was invoked was non-void (had a return value) and so we make
# the value of the current expression equal to the return value # the value of the current expression equal to the return value
# of the command. # of the command.
eval_string.replace "Thread.current[:__pry_cmd_result__].retval\n" @eval_string.replace "Thread.current[:__pry_cmd_result__].retval\n"
end end
true true
else else
@ -436,10 +435,9 @@ class Pry
# Same as process_command, but outputs exceptions to {output} instead of raising. # Same as process_command, but outputs exceptions to {output} instead of raising.
# @param [String] val The line to process. # @param [String] val The line to process.
# @param [String] eval_string The cumulative lines of input
# @return [Boolean] `true` if `val` is a command, `false` otherwise # @return [Boolean] `true` if `val` is a command, `false` otherwise
def process_command_safely(val, eval_string) def process_command_safely(val)
process_command(val, eval_string) process_command(val)
rescue CommandError, Slop::InvalidOptionError, MethodSource::SourceNotFoundError => e rescue CommandError, Slop::InvalidOptionError, MethodSource::SourceNotFoundError => e
output.puts "Error: #{e.message}" output.puts "Error: #{e.message}"
true true
@ -447,13 +445,13 @@ class Pry
# Run the specified command. # Run the specified command.
# @param [String] val The command (and its params) to execute. # @param [String] val The command (and its params) to execute.
# @param [String] eval_string The current input buffer. # @param [Binding] target The binding to use..
# @return [Pry::Command::VOID_VALUE] # @return [Pry::Command::VOID_VALUE]
# @example # @example
# pry_instance.run_command("ls -m") # pry_instance.run_command("ls -m")
def run_command(val, eval_string = "") def run_command(val)
commands.process_line(val, commands.process_line(val,
:eval_string => eval_string, :eval_string => @eval_string,
:target => current_binding, :target => current_binding,
:pry_instance => self, :pry_instance => self,
:output => output :output => output
@ -553,7 +551,7 @@ class Pry
retry retry
# Interrupts are handled in r() because they need to tweak eval_string # Interrupts are handled in r() because they need to tweak @eval_string
# TODO: Refactor this baby. # TODO: Refactor this baby.
rescue Interrupt rescue Interrupt
raise raise
@ -616,10 +614,8 @@ class Pry
end end
# Returns the appropriate prompt to use. # Returns the appropriate prompt to use.
# This method should not need to be invoked directly.
# @param [String] eval_string The current input buffer.
# @return [String] The prompt. # @return [String] The prompt.
def select_prompt(eval_string) def select_prompt
object = current_binding.eval('self') object = current_binding.eval('self')
open_token = @indent.open_delimiters.any? ? @indent.open_delimiters.last : open_token = @indent.open_delimiters.any? ? @indent.open_delimiters.last :
@ -635,12 +631,12 @@ class Pry
:_pry_ => self, :_pry_ => self,
:binding_stack => binding_stack, :binding_stack => binding_stack,
:input_array => input_array, :input_array => input_array,
:eval_string => eval_string, :eval_string => @eval_string,
:cont => !eval_string.empty?) :cont => !@eval_string.empty?)
Pry.critical_section do Pry.critical_section do
# If input buffer is empty then use normal prompt # If input buffer is empty then use normal prompt
if eval_string.empty? if @eval_string.empty?
generate_prompt(Array(prompt).first, c) generate_prompt(Array(prompt).first, c)
# Otherwise use the wait prompt (indicating multi-line expression) # Otherwise use the wait prompt (indicating multi-line expression)