From fb47d612150b47e0a38a64db4324ff8d66f1a0c9 Mon Sep 17 00:00:00 2001 From: John Mair Date: Tue, 16 Aug 2011 13:02:32 +1200 Subject: [PATCH] removed Pry.active_instance from commands and replaced with _pry_ method --- lib/pry/command_context.rb | 1 + lib/pry/command_processor.rb | 1 + lib/pry/default_commands/basic.rb | 10 +++++----- lib/pry/default_commands/input.rb | 8 ++++---- lib/pry/default_commands/introspection.rb | 2 +- lib/pry/default_commands/shell.rb | 12 ++++++------ lib/pry/extended_commands/user_command_api.rb | 6 +++--- 7 files changed, 21 insertions(+), 19 deletions(-) diff --git a/lib/pry/command_context.rb b/lib/pry/command_context.rb index 8bc1d356..743e7045 100644 --- a/lib/pry/command_context.rb +++ b/lib/pry/command_context.rb @@ -10,6 +10,7 @@ class Pry attr_accessor :opts attr_accessor :command_set attr_accessor :command_processor + attr_accessor :_pry_ # Run a command from another command. # @param [String] command_string The string that invokes the command diff --git a/lib/pry/command_processor.rb b/lib/pry/command_processor.rb index 28ca2155..416f2dc4 100644 --- a/lib/pry/command_processor.rb +++ b/lib/pry/command_processor.rb @@ -125,6 +125,7 @@ class Pry context.eval_string = options[:eval_string] context.arg_string = options[:arg_string] context.command_set = commands + context._pry_ = @pry_instance context.command_processor = self diff --git a/lib/pry/default_commands/basic.rb b/lib/pry/default_commands/basic.rb index 28e8be62..1f79b134 100644 --- a/lib/pry/default_commands/basic.rb +++ b/lib/pry/default_commands/basic.rb @@ -8,11 +8,11 @@ class Pry end command "simple-prompt", "Toggle the simple prompt." do - case Pry.active_instance.prompt + case _pry_.prompt when Pry::SIMPLE_PROMPT - Pry.active_instance.pop_prompt + _pry_.pop_prompt else - Pry.active_instance.push_prompt Pry::SIMPLE_PROMPT + _pry_.push_prompt Pry::SIMPLE_PROMPT end end @@ -24,7 +24,7 @@ class Pry next output.puts "Provide a command set name" if command_set.nil? set = target.eval(arg_string) - Pry.active_instance.commands.import set + _pry_.commands.import set end command "reload-method", "Reload the source file that contains the specified method" do |meth_name| @@ -45,7 +45,7 @@ class Pry end command "req", "Require file(s) and expand their paths." do |*args| - args.each { |file_name| require File.expand_path(file_name) } + args.each { |file_name| load File.expand_path(file_name) } end command "reset", "Reset the REPL to a clean state." do diff --git a/lib/pry/default_commands/input.rb b/lib/pry/default_commands/input.rb index 6816040d..a06443bd 100644 --- a/lib/pry/default_commands/input.rb +++ b/lib/pry/default_commands/input.rb @@ -66,7 +66,7 @@ e.g amend-line puts 'hello again' # no line number modifies immediately preced output.puts opt end - opt.on_noopts { Pry.active_instance.input = StringIO.new(arg_string) } + opt.on_noopts { _pry_.input = StringIO.new(arg_string) } end if opts.m? @@ -81,7 +81,7 @@ e.g amend-line puts 'hello again' # no line number modifies immediately preced range = opts.l? ? one_index_range_or_number(opts[:l]) : (0..-1) range = (0..-2) if opts.o? - Pry.active_instance.input = StringIO.new(Array(code.each_line.to_a[range]).join) + _pry_.input = StringIO.new(Array(code.each_line.to_a[range]).join) end if opts.f? @@ -91,7 +91,7 @@ e.g amend-line puts 'hello again' # no line number modifies immediately preced range = opts.l? ? one_index_range_or_number(opts[:l]) : (0..-1) range = (0..-2) if opts.o? - Pry.active_instance.input = StringIO.new(Array(text_array[range]).join) + _pry_.input = StringIO.new(Array(text_array[range]).join) end end @@ -164,7 +164,7 @@ e.g amend-line puts 'hello again' # no line number modifies immediately preced :as => Range, :unless => :grep do |range| actions = Array(history[range]).join("\n") + "\n" - Pry.active_instance.input = StringIO.new(actions) + _pry_.input = StringIO.new(actions) end opt.on "save", "Save history to a file. --save [start..end] output.txt. Pry commands are excluded from saved history.", true, :as => Range diff --git a/lib/pry/default_commands/introspection.rb b/lib/pry/default_commands/introspection.rb index 65ee779d..ed248d12 100644 --- a/lib/pry/default_commands/introspection.rb +++ b/lib/pry/default_commands/introspection.rb @@ -150,7 +150,7 @@ class Pry if opts[:p] silence_warnings do - Pry.active_instance.input = StringIO.new(File.readlines(file_name).join) + _pry_.input = StringIO.new(File.readlines(file_name).join) end elsif should_reload silence_warnings do diff --git a/lib/pry/default_commands/shell.rb b/lib/pry/default_commands/shell.rb index c6b9755f..60c2f05b 100644 --- a/lib/pry/default_commands/shell.rb +++ b/lib/pry/default_commands/shell.rb @@ -20,15 +20,15 @@ class Pry end command "shell-mode", "Toggle shell mode. Bring in pwd prompt and file completion." do - case Pry.active_instance.prompt + case _pry_.prompt when Pry::SHELL_PROMPT - Pry.active_instance.pop_prompt - Pry.active_instance.custom_completions = Pry::DEFAULT_CUSTOM_COMPLETIONS + _pry_.pop_prompt + _pry_.custom_completions = Pry::DEFAULT_CUSTOM_COMPLETIONS else - Pry.active_instance.push_prompt Pry::SHELL_PROMPT - Pry.active_instance.custom_completions = Pry::FILE_COMPLETIONS + _pry_.push_prompt Pry::SHELL_PROMPT + _pry_.custom_completions = Pry::FILE_COMPLETIONS Readline.completion_proc = Pry::InputCompleter.build_completion_proc target, - Pry.active_instance.instance_eval(&Pry::FILE_COMPLETIONS) + _pry_.instance_eval(&Pry::FILE_COMPLETIONS) end end diff --git a/lib/pry/extended_commands/user_command_api.rb b/lib/pry/extended_commands/user_command_api.rb index 6dbac0f4..bfc41563 100644 --- a/lib/pry/extended_commands/user_command_api.rb +++ b/lib/pry/extended_commands/user_command_api.rb @@ -7,7 +7,7 @@ class Pry next output.puts("Provide an arg!") if arg.nil? prime_string = "command #{arg_string}\n" - command_string = Pry.active_instance.r(target, prime_string) + command_string = _pry_.r(target, prime_string) eval_string.replace <<-HERE _pry_.commands.instance_eval do @@ -28,7 +28,7 @@ class Pry load file_name end Pry.config.commands.import target.eval(set_name) - Pry.active_instance.commands.import target.eval(set_name) + _pry_.commands.import target.eval(set_name) set_file_and_dir_locals(file_name) end @@ -44,7 +44,7 @@ class Pry load file_name end Pry.config.commands.import target.eval(set_name) - Pry.active_instance.commands.import target.eval(set_name) + _pry_.commands.import target.eval(set_name) set_file_and_dir_locals(file_name) end