pry 0.9.12.6-i386-mingw32 → 0.10.0-i386-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +702 -0
- data/LICENSE +2 -2
- data/{README.markdown → README.md} +37 -31
- data/lib/pry.rb +38 -151
- data/lib/pry/cli.rb +35 -17
- data/lib/pry/code.rb +19 -63
- data/lib/pry/code/code_file.rb +103 -0
- data/lib/pry/code/code_range.rb +2 -1
- data/lib/pry/code/loc.rb +2 -2
- data/lib/pry/code_object.rb +40 -21
- data/lib/pry/color_printer.rb +55 -0
- data/lib/pry/command.rb +12 -9
- data/lib/pry/command_set.rb +81 -38
- data/lib/pry/commands.rb +1 -1
- data/lib/pry/commands/amend_line.rb +2 -2
- data/lib/pry/commands/bang.rb +1 -1
- data/lib/pry/commands/cat.rb +11 -2
- data/lib/pry/commands/cat/exception_formatter.rb +6 -7
- data/lib/pry/commands/cat/file_formatter.rb +15 -32
- data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
- data/lib/pry/commands/cd.rb +14 -3
- data/lib/pry/commands/change_inspector.rb +27 -0
- data/lib/pry/commands/change_prompt.rb +26 -0
- data/lib/pry/commands/code_collector.rb +4 -4
- data/lib/pry/commands/easter_eggs.rb +3 -3
- data/lib/pry/commands/edit.rb +10 -22
- data/lib/pry/commands/edit/exception_patcher.rb +2 -2
- data/lib/pry/commands/edit/file_and_line_locator.rb +0 -2
- data/lib/pry/commands/exit_program.rb +0 -1
- data/lib/pry/commands/find_method.rb +16 -22
- data/lib/pry/commands/gem_install.rb +5 -2
- data/lib/pry/commands/gem_open.rb +1 -1
- data/lib/pry/commands/gist.rb +10 -11
- data/lib/pry/commands/help.rb +14 -14
- data/lib/pry/commands/hist.rb +27 -8
- data/lib/pry/commands/install_command.rb +14 -12
- data/lib/pry/commands/list_inspectors.rb +35 -0
- data/lib/pry/commands/list_prompts.rb +35 -0
- data/lib/pry/commands/ls.rb +72 -296
- data/lib/pry/commands/ls/constants.rb +47 -0
- data/lib/pry/commands/ls/formatter.rb +49 -0
- data/lib/pry/commands/ls/globals.rb +48 -0
- data/lib/pry/commands/ls/grep.rb +21 -0
- data/lib/pry/commands/ls/instance_vars.rb +39 -0
- data/lib/pry/commands/ls/interrogatable.rb +18 -0
- data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
- data/lib/pry/commands/ls/local_names.rb +35 -0
- data/lib/pry/commands/ls/local_vars.rb +39 -0
- data/lib/pry/commands/ls/ls_entity.rb +70 -0
- data/lib/pry/commands/ls/methods.rb +57 -0
- data/lib/pry/commands/ls/methods_helper.rb +46 -0
- data/lib/pry/commands/ls/self_methods.rb +32 -0
- data/lib/pry/commands/play.rb +44 -10
- data/lib/pry/commands/pry_backtrace.rb +1 -2
- data/lib/pry/commands/raise_up.rb +2 -2
- data/lib/pry/commands/reload_code.rb +16 -19
- data/lib/pry/commands/ri.rb +7 -3
- data/lib/pry/commands/shell_command.rb +18 -13
- data/lib/pry/commands/shell_mode.rb +2 -4
- data/lib/pry/commands/show_doc.rb +5 -0
- data/lib/pry/commands/show_info.rb +8 -13
- data/lib/pry/commands/show_source.rb +15 -3
- data/lib/pry/commands/simple_prompt.rb +1 -1
- data/lib/pry/commands/toggle_color.rb +8 -4
- data/lib/pry/commands/watch_expression.rb +105 -0
- data/lib/pry/commands/watch_expression/expression.rb +38 -0
- data/lib/pry/commands/whereami.rb +18 -10
- data/lib/pry/commands/wtf.rb +3 -3
- data/lib/pry/config.rb +20 -254
- data/lib/pry/config/behavior.rb +139 -0
- data/lib/pry/config/convenience.rb +26 -0
- data/lib/pry/config/default.rb +165 -0
- data/lib/pry/core_extensions.rb +31 -21
- data/lib/pry/editor.rb +107 -103
- data/lib/pry/exceptions.rb +77 -0
- data/lib/pry/helpers/base_helpers.rb +22 -109
- data/lib/pry/helpers/command_helpers.rb +10 -8
- data/lib/pry/helpers/documentation_helpers.rb +1 -2
- data/lib/pry/helpers/text.rb +4 -5
- data/lib/pry/history.rb +46 -45
- data/lib/pry/history_array.rb +6 -1
- data/lib/pry/hooks.rb +9 -29
- data/lib/pry/indent.rb +6 -6
- data/lib/pry/input_completer.rb +242 -0
- data/lib/pry/input_lock.rb +132 -0
- data/lib/pry/inspector.rb +27 -0
- data/lib/pry/last_exception.rb +61 -0
- data/lib/pry/method.rb +82 -87
- data/lib/pry/{commands/edit/method_patcher.rb → method/patcher.rb} +41 -38
- data/lib/pry/module_candidate.rb +4 -14
- data/lib/pry/object_path.rb +82 -0
- data/lib/pry/output.rb +50 -0
- data/lib/pry/pager.rb +193 -48
- data/lib/pry/plugins.rb +1 -1
- data/lib/pry/prompt.rb +26 -0
- data/lib/pry/pry_class.rb +149 -230
- data/lib/pry/pry_instance.rb +302 -413
- data/lib/pry/rbx_path.rb +1 -1
- data/lib/pry/repl.rb +202 -0
- data/lib/pry/repl_file_loader.rb +20 -26
- data/lib/pry/rubygem.rb +13 -5
- data/lib/pry/terminal.rb +2 -1
- data/lib/pry/test/helper.rb +26 -41
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +45 -59
- metadata +62 -225
- data/.document +0 -2
- data/.gitignore +0 -16
- data/.travis.yml +0 -25
- data/.yardopts +0 -1
- data/CHANGELOG +0 -534
- data/CONTRIBUTORS +0 -55
- data/Gemfile +0 -12
- data/Rakefile +0 -140
- data/TODO +0 -117
- data/lib/pry/completion.rb +0 -321
- data/lib/pry/custom_completions.rb +0 -6
- data/lib/pry/rbx_method.rb +0 -13
- data/man/pry.1 +0 -195
- data/man/pry.1.html +0 -204
- data/man/pry.1.ronn +0 -141
- data/pry.gemspec +0 -29
- data/spec/Procfile +0 -3
- data/spec/cli_spec.rb +0 -78
- data/spec/code_object_spec.rb +0 -277
- data/spec/code_spec.rb +0 -219
- data/spec/command_helpers_spec.rb +0 -29
- data/spec/command_integration_spec.rb +0 -644
- data/spec/command_set_spec.rb +0 -627
- data/spec/command_spec.rb +0 -821
- data/spec/commands/amend_line_spec.rb +0 -247
- data/spec/commands/bang_spec.rb +0 -19
- data/spec/commands/cat_spec.rb +0 -164
- data/spec/commands/cd_spec.rb +0 -250
- data/spec/commands/disable_pry_spec.rb +0 -25
- data/spec/commands/edit_spec.rb +0 -727
- data/spec/commands/exit_all_spec.rb +0 -34
- data/spec/commands/exit_program_spec.rb +0 -19
- data/spec/commands/exit_spec.rb +0 -34
- data/spec/commands/find_method_spec.rb +0 -70
- data/spec/commands/gem_list_spec.rb +0 -26
- data/spec/commands/gist_spec.rb +0 -79
- data/spec/commands/help_spec.rb +0 -56
- data/spec/commands/hist_spec.rb +0 -181
- data/spec/commands/jump_to_spec.rb +0 -15
- data/spec/commands/ls_spec.rb +0 -181
- data/spec/commands/play_spec.rb +0 -140
- data/spec/commands/raise_up_spec.rb +0 -56
- data/spec/commands/save_file_spec.rb +0 -177
- data/spec/commands/show_doc_spec.rb +0 -510
- data/spec/commands/show_input_spec.rb +0 -17
- data/spec/commands/show_source_spec.rb +0 -782
- data/spec/commands/whereami_spec.rb +0 -203
- data/spec/completion_spec.rb +0 -241
- data/spec/control_d_handler_spec.rb +0 -58
- data/spec/documentation_helper_spec.rb +0 -73
- data/spec/editor_spec.rb +0 -79
- data/spec/exception_whitelist_spec.rb +0 -21
- data/spec/fixtures/candidate_helper1.rb +0 -11
- data/spec/fixtures/candidate_helper2.rb +0 -8
- data/spec/fixtures/example.erb +0 -5
- data/spec/fixtures/example_nesting.rb +0 -33
- data/spec/fixtures/show_source_doc_examples.rb +0 -15
- data/spec/fixtures/testrc +0 -2
- data/spec/fixtures/testrcbad +0 -2
- data/spec/fixtures/whereami_helper.rb +0 -6
- data/spec/helper.rb +0 -34
- data/spec/helpers/bacon.rb +0 -86
- data/spec/helpers/mock_pry.rb +0 -43
- data/spec/helpers/table_spec.rb +0 -105
- data/spec/history_array_spec.rb +0 -67
- data/spec/hooks_spec.rb +0 -522
- data/spec/indent_spec.rb +0 -301
- data/spec/input_stack_spec.rb +0 -90
- data/spec/method_spec.rb +0 -482
- data/spec/prompt_spec.rb +0 -60
- data/spec/pry_defaults_spec.rb +0 -419
- data/spec/pry_history_spec.rb +0 -99
- data/spec/pry_output_spec.rb +0 -95
- data/spec/pry_spec.rb +0 -515
- data/spec/run_command_spec.rb +0 -25
- data/spec/sticky_locals_spec.rb +0 -157
- data/spec/syntax_checking_spec.rb +0 -81
- data/spec/wrapped_module_spec.rb +0 -261
- data/wiki/Customizing-pry.md +0 -397
- data/wiki/Home.md +0 -4
data/lib/pry/rbx_path.rb
CHANGED
@@ -2,7 +2,7 @@ class Pry
|
|
2
2
|
module RbxPath
|
3
3
|
module_function
|
4
4
|
def is_core_path?(path)
|
5
|
-
path.start_with?("kernel") || path.start_with?("lib")
|
5
|
+
Pry::Helpers::BaseHelpers.rbx? && (path.start_with?("kernel") || path.start_with?("lib")) && File.exist?(convert_path_to_full(path))
|
6
6
|
end
|
7
7
|
|
8
8
|
def convert_path_to_full(path)
|
data/lib/pry/repl.rb
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
class Pry
|
4
|
+
class REPL
|
5
|
+
extend Forwardable
|
6
|
+
def_delegators :@pry, :input, :output
|
7
|
+
|
8
|
+
# @return [Pry] The instance of {Pry} that the user is controlling.
|
9
|
+
attr_accessor :pry
|
10
|
+
|
11
|
+
# Instantiate a new {Pry} instance with the given options, then start a
|
12
|
+
# {REPL} instance wrapping it.
|
13
|
+
# @option options See {Pry#initialize}
|
14
|
+
def self.start(options)
|
15
|
+
new(Pry.new(options)).start
|
16
|
+
end
|
17
|
+
|
18
|
+
# Create an instance of {REPL} wrapping the given {Pry}.
|
19
|
+
# @param [Pry] pry The instance of {Pry} that this {REPL} will control.
|
20
|
+
# @param [Hash] options Options for this {REPL} instance.
|
21
|
+
# @option options [Object] :target The initial target of the session.
|
22
|
+
def initialize(pry, options = {})
|
23
|
+
@pry = pry
|
24
|
+
@indent = Pry::Indent.new
|
25
|
+
|
26
|
+
if options[:target]
|
27
|
+
@pry.push_binding options[:target]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Start the read-eval-print loop.
|
32
|
+
# @return [Object?] If the session throws `:breakout`, return the value
|
33
|
+
# thrown with it.
|
34
|
+
# @raise [Exception] If the session throws `:raise_up`, raise the exception
|
35
|
+
# thrown with it.
|
36
|
+
def start
|
37
|
+
prologue
|
38
|
+
Pry::InputLock.for(:all).with_ownership { repl }
|
39
|
+
ensure
|
40
|
+
epilogue
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
# Set up the repl session.
|
46
|
+
# @return [void]
|
47
|
+
def prologue
|
48
|
+
pry.exec_hook :before_session, pry.output, pry.current_binding, pry
|
49
|
+
|
50
|
+
# Clear the line before starting Pry. This fixes issue #566.
|
51
|
+
if pry.config.correct_indent
|
52
|
+
Kernel.print Pry::Helpers::BaseHelpers.windows_ansi? ? "\e[0F" : "\e[0G"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# The actual read-eval-print loop.
|
57
|
+
#
|
58
|
+
# The {REPL} instance is responsible for reading and looping, whereas the
|
59
|
+
# {Pry} instance is responsible for evaluating user input and printing
|
60
|
+
# return values and command output.
|
61
|
+
#
|
62
|
+
# @return [Object?] If the session throws `:breakout`, return the value
|
63
|
+
# thrown with it.
|
64
|
+
# @raise [Exception] If the session throws `:raise_up`, raise the exception
|
65
|
+
# thrown with it.
|
66
|
+
def repl
|
67
|
+
loop do
|
68
|
+
case val = read
|
69
|
+
when :control_c
|
70
|
+
output.puts ""
|
71
|
+
pry.reset_eval_string
|
72
|
+
when :no_more_input
|
73
|
+
output.puts "" if output.tty?
|
74
|
+
break
|
75
|
+
else
|
76
|
+
output.puts "" if val.nil? && output.tty?
|
77
|
+
return pry.exit_value unless pry.eval(val)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Clean up after the repl session.
|
83
|
+
# @return [void]
|
84
|
+
def epilogue
|
85
|
+
pry.exec_hook :after_session, pry.output, pry.current_binding, pry
|
86
|
+
end
|
87
|
+
|
88
|
+
# Read a line of input from the user.
|
89
|
+
# @return [String] The line entered by the user.
|
90
|
+
# @return [nil] On `<Ctrl-D>`.
|
91
|
+
# @return [:control_c] On `<Ctrl+C>`.
|
92
|
+
# @return [:no_more_input] On EOF.
|
93
|
+
def read
|
94
|
+
@indent.reset if pry.eval_string.empty?
|
95
|
+
current_prompt = pry.select_prompt
|
96
|
+
indentation = pry.config.auto_indent ? @indent.current_prefix : ''
|
97
|
+
|
98
|
+
val = read_line("#{current_prompt}#{indentation}")
|
99
|
+
|
100
|
+
# Return nil for EOF, :no_more_input for error, or :control_c for <Ctrl-C>
|
101
|
+
return val unless String === val
|
102
|
+
|
103
|
+
if pry.config.auto_indent
|
104
|
+
original_val = "#{indentation}#{val}"
|
105
|
+
indented_val = @indent.indent(val)
|
106
|
+
|
107
|
+
if output.tty? && pry.config.correct_indent && Pry::Helpers::BaseHelpers.use_ansi_codes?
|
108
|
+
output.print @indent.correct_indentation(
|
109
|
+
current_prompt, indented_val,
|
110
|
+
original_val.length - indented_val.length
|
111
|
+
)
|
112
|
+
output.flush
|
113
|
+
end
|
114
|
+
else
|
115
|
+
indented_val = val
|
116
|
+
end
|
117
|
+
|
118
|
+
indented_val
|
119
|
+
end
|
120
|
+
|
121
|
+
# Manage switching of input objects on encountering `EOFError`s.
|
122
|
+
# @return [Object] Whatever the given block returns.
|
123
|
+
# @return [:no_more_input] Indicates that no more input can be read.
|
124
|
+
def handle_read_errors
|
125
|
+
should_retry = true
|
126
|
+
exception_count = 0
|
127
|
+
|
128
|
+
begin
|
129
|
+
yield
|
130
|
+
rescue EOFError
|
131
|
+
pry.config.input = Pry.config.input
|
132
|
+
if !should_retry
|
133
|
+
output.puts "Error: Pry ran out of things to read from! " \
|
134
|
+
"Attempting to break out of REPL."
|
135
|
+
return :no_more_input
|
136
|
+
end
|
137
|
+
should_retry = false
|
138
|
+
retry
|
139
|
+
|
140
|
+
# Handle <Ctrl+C> like Bash: empty the current input buffer, but don't
|
141
|
+
# quit. This is only for MRI 1.9; other versions of Ruby don't let you
|
142
|
+
# send Interrupt from within Readline.
|
143
|
+
rescue Interrupt
|
144
|
+
return :control_c
|
145
|
+
|
146
|
+
# If we get a random error when trying to read a line we don't want to
|
147
|
+
# automatically retry, as the user will see a lot of error messages
|
148
|
+
# scroll past and be unable to do anything about it.
|
149
|
+
rescue RescuableException => e
|
150
|
+
puts "Error: #{e.message}"
|
151
|
+
output.puts e.backtrace
|
152
|
+
exception_count += 1
|
153
|
+
if exception_count < 5
|
154
|
+
retry
|
155
|
+
end
|
156
|
+
puts "FATAL: Pry failed to get user input using `#{input}`."
|
157
|
+
puts "To fix this you may be able to pass input and output file " \
|
158
|
+
"descriptors to pry directly. e.g."
|
159
|
+
puts " Pry.config.input = STDIN"
|
160
|
+
puts " Pry.config.output = STDOUT"
|
161
|
+
puts " binding.pry"
|
162
|
+
return :no_more_input
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
# Returns the next line of input to be sent to the {Pry} instance.
|
167
|
+
# @param [String] current_prompt The prompt to use for input.
|
168
|
+
# @return [String?] The next line of input, or `nil` on <Ctrl-D>.
|
169
|
+
def read_line(current_prompt)
|
170
|
+
handle_read_errors do
|
171
|
+
if defined? Coolline and input.is_a? Coolline
|
172
|
+
input.completion_proc = proc do |cool|
|
173
|
+
completions = @pry.complete cool.completed_word
|
174
|
+
completions.compact
|
175
|
+
end
|
176
|
+
elsif input.respond_to? :completion_proc=
|
177
|
+
input.completion_proc = proc do |input|
|
178
|
+
@pry.complete input
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
if defined?(Readline) and input == Readline
|
183
|
+
input_readline(current_prompt, false) # false since we'll add it manually
|
184
|
+
elsif defined? Coolline and input.is_a? Coolline
|
185
|
+
input_readline(current_prompt)
|
186
|
+
else
|
187
|
+
if input.method(:readline).arity == 1
|
188
|
+
input_readline(current_prompt)
|
189
|
+
else
|
190
|
+
input_readline
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def input_readline(*args)
|
197
|
+
Pry::InputLock.for(:all).interruptible_region do
|
198
|
+
input.readline(*args)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
data/lib/pry/repl_file_loader.rb
CHANGED
@@ -15,29 +15,40 @@ class Pry
|
|
15
15
|
full_name = File.expand_path(file_name)
|
16
16
|
raise RuntimeError, "No such file: #{full_name}" if !File.exists?(full_name)
|
17
17
|
|
18
|
-
|
18
|
+
define_additional_commands
|
19
|
+
@content = File.read(full_name)
|
19
20
|
end
|
20
21
|
|
21
22
|
# Switch to interactive mode, i.e take input from the user
|
22
23
|
# and use the regular print and exception handlers.
|
23
24
|
# @param [Pry] _pry_ the Pry instance to make interactive.
|
24
25
|
def interactive_mode(_pry_)
|
25
|
-
_pry_.input = Pry.config.input
|
26
|
-
_pry_.print = Pry.config.print
|
27
|
-
_pry_.exception_handler = Pry.config.exception_handler
|
26
|
+
_pry_.config.input = Pry.config.input
|
27
|
+
_pry_.config.print = Pry.config.print
|
28
|
+
_pry_.config.exception_handler = Pry.config.exception_handler
|
29
|
+
Pry::REPL.new(_pry_).start
|
28
30
|
end
|
29
31
|
|
30
32
|
# Switch to non-interactive mode. Essentially
|
31
33
|
# this means there is no result output
|
32
34
|
# and that the session becomes interactive when an exception is encountered.
|
33
35
|
# @param [Pry] _pry_ the Pry instance to make non-interactive.
|
34
|
-
def non_interactive_mode(_pry_)
|
36
|
+
def non_interactive_mode(_pry_, content)
|
35
37
|
_pry_.print = proc {}
|
36
|
-
_pry_.exception_handler = proc do |o, e,
|
37
|
-
|
38
|
+
_pry_.exception_handler = proc do |o, e, _p_|
|
39
|
+
_p_.run_command "cat --ex"
|
38
40
|
o.puts "...exception encountered, going interactive!"
|
39
41
|
interactive_mode(_pry_)
|
40
42
|
end
|
43
|
+
|
44
|
+
content.lines.each do |line|
|
45
|
+
break unless _pry_.eval line, :generated => true
|
46
|
+
end
|
47
|
+
|
48
|
+
unless _pry_.eval_string.empty?
|
49
|
+
_pry_.output.puts "#{_pry_.eval_string}...exception encountered, going interactive!"
|
50
|
+
interactive_mode(_pry_)
|
51
|
+
end
|
41
52
|
end
|
42
53
|
|
43
54
|
# Define a few extra commands useful for flipping back & forth
|
@@ -46,35 +57,18 @@ class Pry
|
|
46
57
|
s = self
|
47
58
|
|
48
59
|
Pry::Commands.command "make-interactive", "Make the session interactive" do
|
49
|
-
_pry_.input_stack.push _pry_.input
|
50
60
|
s.interactive_mode(_pry_)
|
51
61
|
end
|
52
62
|
|
53
|
-
Pry::Commands.command "make-non-interactive", "Make the session non-interactive" do
|
54
|
-
_pry_.input = _pry_.input_stack.pop
|
55
|
-
s.non_interactive_mode(_pry_)
|
56
|
-
end
|
57
|
-
|
58
63
|
Pry::Commands.command "load-file", "Load another file through the repl" do |file_name|
|
59
|
-
|
60
|
-
_pry_.input_stack.push(_pry_.input)
|
61
|
-
_pry_.input = content
|
64
|
+
s.non_interactive_mode(_pry_, File.read(File.expand_path(file_name)))
|
62
65
|
end
|
63
66
|
end
|
64
67
|
|
65
68
|
# Actually load the file through the REPL by setting file content
|
66
69
|
# as the REPL input stream.
|
67
70
|
def load
|
68
|
-
Pry.
|
69
|
-
define_additional_commands
|
70
|
-
|
71
|
-
Pry.config.hooks.add_hook(:when_started, :start_non_interactively) do |o, t, _pry_|
|
72
|
-
non_interactive_mode(_pry_)
|
73
|
-
end
|
74
|
-
|
75
|
-
Pry.start(Pry.toplevel_binding,
|
76
|
-
:input => @content,
|
77
|
-
:input_stack => [StringIO.new("exit-all\n")])
|
71
|
+
non_interactive_mode(Pry.new, @content)
|
78
72
|
end
|
79
73
|
end
|
80
74
|
end
|
data/lib/pry/rubygem.rb
CHANGED
@@ -23,9 +23,9 @@ class Pry
|
|
23
23
|
Gem.source_index.find_name(name)
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
first_spec = specs.sort_by{ |spec| Gem::Version.new(spec.version) }.last
|
27
27
|
|
28
|
-
|
28
|
+
first_spec or raise CommandError, "Gem `#{name}` not found"
|
29
29
|
end
|
30
30
|
|
31
31
|
# List gems matching a pattern.
|
@@ -57,14 +57,22 @@ class Pry
|
|
57
57
|
# @param [String] name
|
58
58
|
# @return [void]
|
59
59
|
def install(name)
|
60
|
-
|
60
|
+
gemrc_opts = Gem.configuration['gem'].split(' ')
|
61
|
+
destination = if gemrc_opts.include?('--user-install')
|
62
|
+
Gem.user_dir
|
63
|
+
elsif File.writable?(Gem.dir)
|
64
|
+
Gem.dir
|
65
|
+
else
|
66
|
+
Gem.user_dir
|
67
|
+
end
|
61
68
|
installer = Gem::DependencyInstaller.new(:install_dir => destination)
|
62
69
|
installer.install(name)
|
63
70
|
rescue Errno::EACCES
|
64
71
|
raise CommandError,
|
65
|
-
"Insufficient permissions to install
|
72
|
+
"Insufficient permissions to install #{ Pry::Helpers::Text.green(name) }."
|
66
73
|
rescue Gem::GemNotFoundException
|
67
|
-
raise CommandError,
|
74
|
+
raise CommandError,
|
75
|
+
"Gem #{ Pry::Helpers::Text.green(name) } not found. Aborting installation."
|
68
76
|
else
|
69
77
|
Gem.refresh
|
70
78
|
end
|
data/lib/pry/terminal.rb
CHANGED
@@ -44,7 +44,8 @@ class Pry::Terminal
|
|
44
44
|
require 'io/console'
|
45
45
|
$stdout.winsize if $stdout.tty? and $stdout.respond_to?(:winsize)
|
46
46
|
rescue LoadError
|
47
|
-
# They
|
47
|
+
# They probably don't have the io/console stdlib or the io-console gem.
|
48
|
+
# We'll keep trying.
|
48
49
|
end
|
49
50
|
|
50
51
|
def screen_size_according_to_env
|
data/lib/pry/test/helper.rb
CHANGED
@@ -7,14 +7,14 @@ class << Pry
|
|
7
7
|
def reset_defaults
|
8
8
|
orig_reset_defaults
|
9
9
|
|
10
|
-
Pry.color = false
|
11
|
-
Pry.pager = false
|
10
|
+
Pry.config.color = false
|
11
|
+
Pry.config.pager = false
|
12
12
|
Pry.config.should_load_rc = false
|
13
13
|
Pry.config.should_load_local_rc= false
|
14
14
|
Pry.config.should_load_plugins = false
|
15
15
|
Pry.config.history.should_load = false
|
16
16
|
Pry.config.history.should_save = false
|
17
|
-
Pry.config.
|
17
|
+
Pry.config.correct_indent = false
|
18
18
|
Pry.config.hooks = Pry::Hooks.new
|
19
19
|
Pry.config.collision_warning = false
|
20
20
|
end
|
@@ -47,10 +47,6 @@ module PryTestHelpers
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
def mri18_and_no_real_source_location?
|
51
|
-
Pry::Helpers::BaseHelpers.mri_18? && !(Method.instance_method(:source_location).owner == Method)
|
52
|
-
end
|
53
|
-
|
54
50
|
# Open a temp file and yield it to the block, closing it after
|
55
51
|
# @return [String] The path of the temp file
|
56
52
|
def temp_file(ext='.rb')
|
@@ -67,16 +63,15 @@ module PryTestHelpers
|
|
67
63
|
|
68
64
|
def mock_command(cmd, args=[], opts={})
|
69
65
|
output = StringIO.new
|
70
|
-
|
66
|
+
pry = Pry.new(output: output)
|
67
|
+
ret = cmd.new(opts.merge(pry_instance: pry, :output => output)).call_safely(*args)
|
71
68
|
Struct.new(:output, :return).new(output.string, ret)
|
72
69
|
end
|
73
70
|
|
74
71
|
def mock_exception(*mock_backtrace)
|
75
|
-
|
76
|
-
|
77
|
-
define_method(:backtrace) { mock_backtrace }
|
72
|
+
StandardError.new.tap do |e|
|
73
|
+
e.define_singleton_method(:backtrace) { mock_backtrace }
|
78
74
|
end
|
79
|
-
e
|
80
75
|
end
|
81
76
|
end
|
82
77
|
|
@@ -101,18 +96,17 @@ def pry_eval(*eval_strs)
|
|
101
96
|
end
|
102
97
|
|
103
98
|
class PryTester
|
99
|
+
extend Forwardable
|
100
|
+
|
104
101
|
attr_reader :pry, :out
|
105
102
|
|
106
|
-
|
107
|
-
@pry = Pry.new(options)
|
103
|
+
def_delegators :@pry, :eval_string, :eval_string=
|
108
104
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
@pry.inject_sticky_locals(target)
|
113
|
-
end
|
105
|
+
def initialize(target = TOPLEVEL_BINDING, options = {})
|
106
|
+
@pry = Pry.new(options.merge(:target => target))
|
107
|
+
@history = options[:history]
|
114
108
|
|
115
|
-
@pry.
|
109
|
+
@pry.inject_sticky_locals!
|
116
110
|
reset_output
|
117
111
|
end
|
118
112
|
|
@@ -122,6 +116,8 @@ class PryTester
|
|
122
116
|
|
123
117
|
strs.flatten.each do |str|
|
124
118
|
str = "#{str.strip}\n"
|
119
|
+
@history.push str if @history
|
120
|
+
|
125
121
|
if @pry.process_command(str)
|
126
122
|
result = last_command_result_or_output
|
127
123
|
else
|
@@ -132,43 +128,32 @@ class PryTester
|
|
132
128
|
result
|
133
129
|
end
|
134
130
|
|
135
|
-
def
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
# TODO: eliminate duplication with Pry#repl
|
140
|
-
def simulate_repl
|
141
|
-
didnt_exit = nil
|
142
|
-
break_data = nil
|
143
|
-
|
144
|
-
didnt_exit = catch(:didnt_exit) do
|
145
|
-
break_data = catch(:breakout) do
|
146
|
-
yield self
|
147
|
-
throw(:didnt_exit, true)
|
148
|
-
end
|
149
|
-
nil
|
131
|
+
def push(*lines)
|
132
|
+
Array(lines).flatten.each do |line|
|
133
|
+
@pry.eval(line)
|
150
134
|
end
|
135
|
+
end
|
151
136
|
|
152
|
-
|
153
|
-
|
137
|
+
def push_binding(context)
|
138
|
+
@pry.push_binding context
|
154
139
|
end
|
155
140
|
|
156
141
|
def last_output
|
157
142
|
@out.string if @out
|
158
143
|
end
|
159
144
|
|
160
|
-
def process_command(command_str
|
161
|
-
@pry.process_command(command_str
|
145
|
+
def process_command(command_str)
|
146
|
+
@pry.process_command(command_str) or raise "Not a valid command"
|
162
147
|
last_command_result_or_output
|
163
148
|
end
|
164
149
|
|
165
|
-
protected
|
166
|
-
|
167
150
|
def last_command_result
|
168
151
|
result = Pry.current[:pry_cmd_result]
|
169
152
|
result.retval if result
|
170
153
|
end
|
171
154
|
|
155
|
+
protected
|
156
|
+
|
172
157
|
def last_command_result_or_output
|
173
158
|
result = last_command_result
|
174
159
|
if result != Pry::Command::VOID_VALUE
|