pry 0.12.2 → 0.14.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +158 -1
- data/LICENSE +1 -1
- data/README.md +331 -269
- data/bin/pry +5 -0
- data/lib/pry/basic_object.rb +8 -4
- data/lib/pry/block_command.rb +22 -0
- data/lib/pry/class_command.rb +194 -0
- data/lib/pry/cli.rb +44 -55
- data/lib/pry/code/code_file.rb +28 -24
- data/lib/pry/code/code_range.rb +4 -2
- data/lib/pry/code/loc.rb +15 -8
- data/lib/pry/code.rb +40 -28
- data/lib/pry/code_object.rb +40 -38
- data/lib/pry/color_printer.rb +47 -46
- data/lib/pry/command.rb +166 -369
- data/lib/pry/command_set.rb +76 -73
- data/lib/pry/command_state.rb +31 -0
- data/lib/pry/commands/amend_line.rb +86 -81
- data/lib/pry/commands/bang.rb +18 -14
- data/lib/pry/commands/bang_pry.rb +15 -11
- data/lib/pry/commands/cat/abstract_formatter.rb +23 -18
- data/lib/pry/commands/cat/exception_formatter.rb +71 -60
- data/lib/pry/commands/cat/file_formatter.rb +55 -49
- data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
- data/lib/pry/commands/cat.rb +61 -54
- data/lib/pry/commands/cd.rb +40 -35
- data/lib/pry/commands/change_inspector.rb +29 -22
- data/lib/pry/commands/change_prompt.rb +44 -39
- data/lib/pry/commands/clear_screen.rb +16 -10
- data/lib/pry/commands/code_collector.rb +148 -133
- data/lib/pry/commands/disable_pry.rb +23 -19
- data/lib/pry/commands/easter_eggs.rb +19 -30
- data/lib/pry/commands/edit/exception_patcher.rb +21 -17
- data/lib/pry/commands/edit/file_and_line_locator.rb +34 -23
- data/lib/pry/commands/edit.rb +184 -161
- data/lib/pry/commands/exit.rb +39 -35
- data/lib/pry/commands/exit_all.rb +24 -20
- data/lib/pry/commands/exit_program.rb +20 -16
- data/lib/pry/commands/find_method.rb +168 -160
- data/lib/pry/commands/fix_indent.rb +16 -12
- data/lib/pry/commands/help.rb +140 -133
- data/lib/pry/commands/hist.rb +151 -150
- data/lib/pry/commands/import_set.rb +20 -16
- data/lib/pry/commands/jump_to.rb +25 -21
- data/lib/pry/commands/list_inspectors.rb +35 -28
- data/lib/pry/commands/ls/constants.rb +59 -42
- data/lib/pry/commands/ls/formatter.rb +50 -46
- data/lib/pry/commands/ls/globals.rb +38 -34
- data/lib/pry/commands/ls/grep.rb +17 -13
- data/lib/pry/commands/ls/instance_vars.rb +29 -27
- data/lib/pry/commands/ls/interrogatable.rb +18 -12
- data/lib/pry/commands/ls/jruby_hacks.rb +47 -41
- data/lib/pry/commands/ls/local_names.rb +26 -22
- data/lib/pry/commands/ls/local_vars.rb +38 -28
- data/lib/pry/commands/ls/ls_entity.rb +47 -51
- data/lib/pry/commands/ls/methods.rb +44 -43
- data/lib/pry/commands/ls/methods_helper.rb +46 -42
- data/lib/pry/commands/ls/self_methods.rb +23 -22
- data/lib/pry/commands/ls.rb +124 -102
- data/lib/pry/commands/nesting.rb +21 -17
- data/lib/pry/commands/play.rb +93 -82
- data/lib/pry/commands/pry_backtrace.rb +22 -17
- data/lib/pry/commands/pry_version.rb +15 -11
- data/lib/pry/commands/raise_up.rb +27 -22
- data/lib/pry/commands/reload_code.rb +60 -48
- data/lib/pry/commands/reset.rb +16 -12
- data/lib/pry/commands/ri.rb +55 -45
- data/lib/pry/commands/save_file.rb +45 -43
- data/lib/pry/commands/shell_command.rb +51 -51
- data/lib/pry/commands/shell_mode.rb +21 -17
- data/lib/pry/commands/show_doc.rb +80 -68
- data/lib/pry/commands/show_info.rb +189 -171
- data/lib/pry/commands/show_input.rb +16 -11
- data/lib/pry/commands/show_source.rb +110 -45
- data/lib/pry/commands/stat.rb +35 -31
- data/lib/pry/commands/switch_to.rb +21 -15
- data/lib/pry/commands/toggle_color.rb +20 -16
- data/lib/pry/commands/watch_expression/expression.rb +32 -27
- data/lib/pry/commands/watch_expression.rb +89 -86
- data/lib/pry/commands/whereami.rb +156 -148
- data/lib/pry/commands/wtf.rb +75 -50
- data/lib/pry/config/attributable.rb +22 -0
- data/lib/pry/config/lazy_value.rb +29 -0
- data/lib/pry/config/memoized_value.rb +34 -0
- data/lib/pry/config/value.rb +24 -0
- data/lib/pry/config.rb +307 -25
- data/lib/pry/control_d_handler.rb +28 -0
- data/lib/pry/core_extensions.rb +9 -7
- data/lib/pry/editor.rb +48 -21
- data/lib/pry/env.rb +18 -0
- data/lib/pry/exception_handler.rb +43 -0
- data/lib/pry/exceptions.rb +13 -16
- data/lib/pry/forwardable.rb +5 -1
- data/lib/pry/helpers/base_helpers.rb +68 -197
- data/lib/pry/helpers/command_helpers.rb +50 -61
- data/lib/pry/helpers/documentation_helpers.rb +21 -13
- data/lib/pry/helpers/options_helpers.rb +14 -7
- data/lib/pry/helpers/platform.rb +7 -5
- data/lib/pry/helpers/table.rb +33 -26
- data/lib/pry/helpers/text.rb +22 -19
- data/lib/pry/helpers.rb +2 -0
- data/lib/pry/history.rb +48 -56
- data/lib/pry/hooks.rb +21 -12
- data/lib/pry/indent.rb +54 -50
- data/lib/pry/input_completer.rb +248 -230
- data/lib/pry/input_lock.rb +8 -9
- data/lib/pry/inspector.rb +36 -24
- data/lib/pry/last_exception.rb +45 -45
- data/lib/pry/method/disowned.rb +16 -4
- data/lib/pry/method/patcher.rb +12 -3
- data/lib/pry/method/weird_method_locator.rb +68 -44
- data/lib/pry/method.rb +141 -94
- data/lib/pry/object_path.rb +33 -25
- data/lib/pry/output.rb +121 -35
- data/lib/pry/pager.rb +41 -42
- data/lib/pry/prompt.rb +123 -54
- data/lib/pry/pry_class.rb +61 -103
- data/lib/pry/pry_instance.rb +217 -215
- data/lib/pry/repl.rb +18 -22
- data/lib/pry/repl_file_loader.rb +27 -21
- data/lib/pry/ring.rb +11 -6
- data/lib/pry/slop/commands.rb +164 -169
- data/lib/pry/slop/option.rb +172 -168
- data/lib/pry/slop.rb +574 -563
- data/lib/pry/syntax_highlighter.rb +26 -0
- data/lib/pry/system_command_handler.rb +17 -0
- data/lib/pry/testable/evalable.rb +21 -12
- data/lib/pry/testable/mockable.rb +18 -10
- data/lib/pry/testable/pry_tester.rb +71 -56
- data/lib/pry/testable/utility.rb +29 -21
- data/lib/pry/testable/variables.rb +49 -43
- data/lib/pry/testable.rb +59 -61
- data/lib/pry/version.rb +3 -1
- data/lib/pry/warning.rb +27 -0
- data/lib/pry/wrapped_module/candidate.rb +21 -14
- data/lib/pry/wrapped_module.rb +51 -42
- data/lib/pry.rb +132 -119
- metadata +34 -34
- data/lib/pry/commands/disabled_commands.rb +0 -2
- data/lib/pry/commands/gem_cd.rb +0 -26
- data/lib/pry/commands/gem_install.rb +0 -32
- data/lib/pry/commands/gem_list.rb +0 -33
- data/lib/pry/commands/gem_open.rb +0 -29
- data/lib/pry/commands/gem_readme.rb +0 -25
- data/lib/pry/commands/gem_search.rb +0 -40
- data/lib/pry/commands/gem_stats.rb +0 -83
- data/lib/pry/commands/gist.rb +0 -102
- data/lib/pry/commands/install_command.rb +0 -54
- data/lib/pry/commands.rb +0 -6
- data/lib/pry/config/behavior.rb +0 -255
- data/lib/pry/config/convenience.rb +0 -28
- data/lib/pry/config/default.rb +0 -159
- data/lib/pry/config/memoization.rb +0 -48
- data/lib/pry/platform.rb +0 -91
- data/lib/pry/plugins.rb +0 -122
- data/lib/pry/rubygem.rb +0 -84
- data/lib/pry/terminal.rb +0 -91
data/lib/pry/config.rb
CHANGED
@@ -1,35 +1,317 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ostruct'
|
4
|
+
|
1
5
|
class Pry
|
2
|
-
#
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
#
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
#
|
14
|
-
|
6
|
+
# @api private
|
7
|
+
class Config
|
8
|
+
extend Attributable
|
9
|
+
|
10
|
+
# @return [IO, #readline] he object from which Pry retrieves its lines of
|
11
|
+
# input
|
12
|
+
attribute :input
|
13
|
+
|
14
|
+
# @return [IO, #puts] where Pry should output results provided by {input}
|
15
|
+
attribute :output
|
16
|
+
|
17
|
+
# @return [Pry::CommandSet]
|
18
|
+
attribute :commands
|
19
|
+
|
20
|
+
# @return [Proc] the printer for Ruby expressions (not commands)
|
21
|
+
attribute :print
|
22
|
+
|
23
|
+
# @return [Proc] the printer for exceptions
|
24
|
+
attribute :exception_handler
|
25
|
+
|
26
|
+
# @return [Array] Exception that Pry shouldn't rescue
|
27
|
+
attribute :unrescued_exceptions
|
28
|
+
|
29
|
+
# @deprecated
|
30
|
+
# @return [Array] Exception that Pry shouldn't rescue
|
31
|
+
attribute :exception_whitelist
|
32
|
+
|
33
|
+
# @return [Integer] The number of lines of context to show before and after
|
34
|
+
# exceptions
|
35
|
+
attribute :default_window_size
|
36
|
+
|
37
|
+
# @return [Pry::Hooks]
|
38
|
+
attribute :hooks
|
39
|
+
|
40
|
+
# @return [Pry::Prompt]
|
41
|
+
attribute :prompt
|
42
|
+
|
43
|
+
# @return [String] The display name that is part of the prompt
|
44
|
+
attribute :prompt_name
|
45
|
+
|
46
|
+
# @return [Array<Object>] the list of objects that are known to have a
|
47
|
+
# 1-line #inspect output suitable for prompt
|
48
|
+
attribute :prompt_safe_contexts
|
49
|
+
|
50
|
+
# If it is a String, then that String is used as the shell
|
51
|
+
# command to invoke the editor.
|
15
52
|
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
53
|
+
# If it responds to #call is callable then `file`, `line`, and `reloading`
|
54
|
+
# are passed to it. `reloading` indicates whether Pry will be reloading code
|
55
|
+
# after the shell command returns. All parameters are optional.
|
56
|
+
# @return [String, #call]
|
57
|
+
attribute :editor
|
58
|
+
|
59
|
+
# A string that must precede all commands. For example, if is is
|
60
|
+
# set to "%", the "cd" command must be invoked as "%cd").
|
61
|
+
# @return [String]
|
62
|
+
attribute :command_prefix
|
63
|
+
|
64
|
+
# @return [Boolean]
|
65
|
+
attribute :color
|
66
|
+
|
67
|
+
# @return [Boolean]
|
68
|
+
attribute :pager
|
69
|
+
|
70
|
+
# @return [Boolean] whether the global ~/.pryrc should be loaded
|
71
|
+
attribute :should_load_rc
|
72
|
+
|
73
|
+
# @return [Boolean] whether the local ./.pryrc should be loaded
|
74
|
+
attribute :should_load_local_rc
|
75
|
+
|
76
|
+
# @return [Boolean] whether to load files specified with the -r flag
|
77
|
+
attribute :should_load_requires
|
78
|
+
|
79
|
+
# @return [Boolean] whether to disable edit-method's auto-reloading behavior
|
80
|
+
attribute :disable_auto_reload
|
81
|
+
|
82
|
+
# Whether Pry should trap SIGINT and cause it to raise an Interrupt
|
83
|
+
# exception. This is only useful on JRuby, MRI does this for us.
|
84
|
+
# @return [Boolean]
|
85
|
+
attribute :should_trap_interrupts
|
86
|
+
|
87
|
+
# @return [Pry::History]
|
88
|
+
attribute :history
|
89
|
+
|
90
|
+
# @return [Boolean]
|
91
|
+
attribute :history_save
|
92
|
+
|
93
|
+
# @return [Boolean]
|
94
|
+
attribute :history_load
|
95
|
+
|
96
|
+
# @return [String]
|
97
|
+
attribute :history_file
|
98
|
+
|
99
|
+
# @return [Array<String,Regexp>]
|
100
|
+
attribute :history_ignorelist
|
101
|
+
|
102
|
+
# @return [Array<String>] Ruby files to be required
|
103
|
+
attribute :requires
|
104
|
+
|
105
|
+
# @return [Integer] how many input/output lines to keep in memory
|
106
|
+
attribute :memory_size
|
107
|
+
|
108
|
+
# @return [Proc] The proc that runs system commands
|
109
|
+
attribute :system
|
110
|
+
|
111
|
+
# @return [Boolean]
|
112
|
+
attribute :auto_indent
|
113
|
+
|
114
|
+
# @return [Boolean]
|
115
|
+
attribute :correct_indent
|
22
116
|
|
23
|
-
|
24
|
-
|
25
|
-
|
117
|
+
# @return [Boolean] whether or not display a warning when a command name
|
118
|
+
# collides with a method/local in the current context.
|
119
|
+
attribute :collision_warning
|
120
|
+
|
121
|
+
# @return [Hash{Symbol=>Proc}]
|
122
|
+
attribute :extra_sticky_locals
|
123
|
+
|
124
|
+
# @return [#build_completion_proc] a completer to use
|
125
|
+
attribute :completer
|
126
|
+
|
127
|
+
# @return [Boolean] suppresses whereami output on `binding.pry`
|
128
|
+
attribute :quiet
|
129
|
+
|
130
|
+
# @return [Boolean] displays a warning about experience improvement on
|
131
|
+
# Windows
|
132
|
+
attribute :windows_console_warning
|
133
|
+
|
134
|
+
# @return [Proc]
|
135
|
+
attribute :command_completions
|
136
|
+
|
137
|
+
# @return [Proc]
|
138
|
+
attribute :file_completions
|
139
|
+
|
140
|
+
# @return [Hash]
|
141
|
+
attribute :ls
|
142
|
+
|
143
|
+
# @return [String] a line of code to execute in context before the session
|
144
|
+
# starts
|
145
|
+
attribute :exec_string
|
146
|
+
|
147
|
+
# @return [String]
|
148
|
+
attribute :output_prefix
|
149
|
+
|
150
|
+
# @return [String]
|
151
|
+
# @since v0.13.0
|
152
|
+
attribute :rc_file
|
153
|
+
|
154
|
+
def initialize
|
155
|
+
merge!(
|
156
|
+
input: MemoizedValue.new { lazy_readline },
|
157
|
+
output: $stdout.tap { |out| out.sync = true },
|
158
|
+
commands: Pry::Commands,
|
159
|
+
prompt_name: 'pry',
|
160
|
+
prompt: Pry::Prompt[:default],
|
161
|
+
prompt_safe_contexts: [String, Numeric, Symbol, nil, true, false],
|
162
|
+
print: Pry::ColorPrinter.method(:default),
|
163
|
+
quiet: false,
|
164
|
+
exception_handler: Pry::ExceptionHandler.method(:handle_exception),
|
165
|
+
|
166
|
+
unrescued_exceptions: [
|
167
|
+
::SystemExit, ::SignalException, Pry::TooSafeException
|
168
|
+
],
|
169
|
+
|
170
|
+
exception_whitelist: MemoizedValue.new do
|
171
|
+
output.puts(
|
172
|
+
'[warning] Pry.config.exception_whitelist is deprecated, ' \
|
173
|
+
'please use Pry.config.unrescued_exceptions instead.'
|
174
|
+
)
|
175
|
+
unrescued_exceptions
|
176
|
+
end,
|
177
|
+
|
178
|
+
hooks: Pry::Hooks.default,
|
179
|
+
pager: true,
|
180
|
+
system: Pry::SystemCommandHandler.method(:default),
|
181
|
+
color: Pry::Helpers::BaseHelpers.use_ansi_codes?,
|
182
|
+
default_window_size: 5,
|
183
|
+
editor: Pry::Editor.default,
|
184
|
+
rc_file: default_rc_file,
|
185
|
+
should_load_rc: true,
|
186
|
+
should_load_local_rc: true,
|
187
|
+
should_trap_interrupts: Pry::Helpers::Platform.jruby?,
|
188
|
+
disable_auto_reload: false,
|
189
|
+
command_prefix: '',
|
190
|
+
auto_indent: Pry::Helpers::BaseHelpers.use_ansi_codes?,
|
191
|
+
correct_indent: true,
|
192
|
+
collision_warning: false,
|
193
|
+
output_prefix: '=> ',
|
194
|
+
requires: [],
|
195
|
+
should_load_requires: true,
|
196
|
+
windows_console_warning: true,
|
197
|
+
control_d_handler: Pry::ControlDHandler.method(:default),
|
198
|
+
memory_size: 100,
|
199
|
+
extra_sticky_locals: {},
|
200
|
+
command_completions: proc { commands.keys },
|
201
|
+
file_completions: proc { Dir['.'] },
|
202
|
+
ls: OpenStruct.new(Pry::Command::Ls::DEFAULT_OPTIONS),
|
203
|
+
completer: Pry::InputCompleter,
|
204
|
+
history_save: true,
|
205
|
+
history_load: true,
|
206
|
+
history_file: Pry::History.default_file,
|
207
|
+
history_ignorelist: [],
|
208
|
+
history: MemoizedValue.new do
|
209
|
+
if defined?(input::HISTORY)
|
210
|
+
Pry::History.new(history: input::HISTORY)
|
211
|
+
else
|
212
|
+
Pry::History.new
|
213
|
+
end
|
214
|
+
end,
|
215
|
+
exec_string: ''
|
216
|
+
)
|
217
|
+
|
218
|
+
@custom_attrs = {}
|
219
|
+
end
|
220
|
+
|
221
|
+
def merge!(config_hash)
|
222
|
+
config_hash.each_pair { |attr, value| __send__("#{attr}=", value) }
|
223
|
+
self
|
224
|
+
end
|
225
|
+
|
226
|
+
def merge(config_hash)
|
227
|
+
dup.merge!(config_hash)
|
228
|
+
end
|
229
|
+
|
230
|
+
def []=(attr, value)
|
231
|
+
@custom_attrs[attr.to_s] = Config::Value.new(value)
|
232
|
+
end
|
233
|
+
|
234
|
+
def [](attr)
|
235
|
+
@custom_attrs[attr.to_s].call
|
236
|
+
end
|
237
|
+
|
238
|
+
# rubocop:disable Style/MethodMissingSuper
|
239
|
+
def method_missing(method_name, *args, &_block)
|
240
|
+
name = method_name.to_s
|
241
|
+
|
242
|
+
if name.end_with?('=')
|
243
|
+
self[name[0..-2]] = args.first
|
244
|
+
elsif @custom_attrs.key?(name)
|
245
|
+
self[name]
|
26
246
|
end
|
27
247
|
end
|
248
|
+
# rubocop:enable Style/MethodMissingSuper
|
28
249
|
|
29
|
-
|
250
|
+
def respond_to_missing?(method_name, include_all = false)
|
251
|
+
@custom_attrs.key?(method_name.to_s.tr('=', '')) || super
|
252
|
+
end
|
30
253
|
|
31
|
-
def
|
32
|
-
|
254
|
+
def initialize_dup(other)
|
255
|
+
super
|
256
|
+
@custom_attrs = @custom_attrs.dup
|
257
|
+
end
|
258
|
+
|
259
|
+
attr_reader :control_d_handler
|
260
|
+
def control_d_handler=(value)
|
261
|
+
proxy_proc =
|
262
|
+
if value.arity == 2
|
263
|
+
Pry::Warning.warn(
|
264
|
+
"control_d_handler's arity of 2 parameters was deprecated " \
|
265
|
+
'(eval_string, pry_instance). Now it gets passed just 1 ' \
|
266
|
+
'parameter (pry_instance)'
|
267
|
+
)
|
268
|
+
proc do |*args|
|
269
|
+
if args.size == 2
|
270
|
+
value.call(args.first, args[1])
|
271
|
+
else
|
272
|
+
value.call(args.first.eval_string, args.first)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
else
|
276
|
+
proc do |*args|
|
277
|
+
if args.size == 2
|
278
|
+
value.call(args[1])
|
279
|
+
else
|
280
|
+
value.call(args.first)
|
281
|
+
end
|
282
|
+
end
|
283
|
+
end
|
284
|
+
@control_d_handler = proxy_proc
|
285
|
+
end
|
286
|
+
|
287
|
+
private
|
288
|
+
|
289
|
+
def lazy_readline
|
290
|
+
require 'readline'
|
291
|
+
::Readline
|
292
|
+
rescue LoadError
|
293
|
+
output.puts(
|
294
|
+
"Sorry, you can't use Pry without Readline or a compatible library. \n" \
|
295
|
+
"Possible solutions: \n" \
|
296
|
+
" * Rebuild Ruby with Readline support using `--with-readline` \n" \
|
297
|
+
" * Use the rb-readline gem, which is a pure-Ruby port of Readline \n" \
|
298
|
+
" * Use the pry-coolline gem, a pure-ruby alternative to Readline"
|
299
|
+
)
|
300
|
+
raise
|
301
|
+
end
|
302
|
+
|
303
|
+
def default_rc_file
|
304
|
+
if (pryrc = Pry::Env['PRYRC'])
|
305
|
+
pryrc
|
306
|
+
elsif (xdg_home = Pry::Env['XDG_CONFIG_HOME'])
|
307
|
+
# See XDG Base Directory Specification at
|
308
|
+
# https://standards.freedesktop.org/basedir-spec/basedir-spec-0.8.html
|
309
|
+
xdg_home + '/pry/pryrc'
|
310
|
+
elsif File.exist?(File.expand_path('~/.pryrc'))
|
311
|
+
'~/.pryrc'
|
312
|
+
else
|
313
|
+
'~/.config/pry/pryrc'
|
314
|
+
end
|
33
315
|
end
|
34
316
|
end
|
35
317
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Pry
|
4
|
+
# @api private
|
5
|
+
# @since v0.13.0
|
6
|
+
module ControlDHandler
|
7
|
+
# Deal with the ^D key being pressed. Different behaviour in different
|
8
|
+
# cases:
|
9
|
+
# 1. In an expression behave like `!` command.
|
10
|
+
# 2. At top-level session behave like `exit` command.
|
11
|
+
# 3. In a nested session behave like `cd ..`.
|
12
|
+
def self.default(pry_instance)
|
13
|
+
if !pry_instance.eval_string.empty?
|
14
|
+
# Clear input buffer.
|
15
|
+
pry_instance.eval_string = ''
|
16
|
+
elsif pry_instance.binding_stack.one?
|
17
|
+
pry_instance.binding_stack.clear
|
18
|
+
throw(:breakout)
|
19
|
+
else
|
20
|
+
# Otherwise, saves current binding stack as old stack and pops last
|
21
|
+
# binding out of binding stack (the old stack still has that binding).
|
22
|
+
cd_state = Pry::CommandState.default.state_for('cd')
|
23
|
+
cd_state.old_stack = pry_instance.binding_stack.dup
|
24
|
+
pry_instance.binding_stack.pop
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/pry/core_extensions.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
4
|
# @return [Array] Code of the method used when implementing Pry's
|
3
5
|
# __binding__, along with line indication to be used with instance_eval (and
|
4
6
|
# friends).
|
5
7
|
#
|
6
8
|
# @see Object#__binding__
|
7
|
-
BINDING_METHOD_IMPL = [<<-METHOD, __FILE__, __LINE__ + 1]
|
9
|
+
BINDING_METHOD_IMPL = [<<-METHOD, __FILE__, __LINE__ + 1].freeze
|
8
10
|
# Get a binding with 'self' set to self, and no locals.
|
9
11
|
#
|
10
12
|
# The default definee is determined by the context in which the
|
@@ -39,7 +41,7 @@ class Object
|
|
39
41
|
# my_method()
|
40
42
|
# @see Pry.start
|
41
43
|
def pry(object = nil, hash = {})
|
42
|
-
if object.nil? || Hash === object
|
44
|
+
if object.nil? || Hash === object # rubocop:disable Style/CaseEquality
|
43
45
|
Pry.start(self, object || {})
|
44
46
|
else
|
45
47
|
Pry.start(object, hash)
|
@@ -81,10 +83,10 @@ class Object
|
|
81
83
|
# This fixes the following two spec failures, at https://travis-ci.org/pry/pry/jobs/274470002
|
82
84
|
# 1) ./spec/pry_spec.rb:360:in `block in (root)'
|
83
85
|
# 2) ./spec/pry_spec.rb:366:in `block in (root)'
|
84
|
-
return class_eval { binding } if Pry::Helpers::Platform.jruby?
|
86
|
+
return class_eval { binding } if Pry::Helpers::Platform.jruby? && name.nil?
|
85
87
|
|
86
88
|
# class_eval sets both self and the default definee to this class.
|
87
|
-
return class_eval("binding")
|
89
|
+
return class_eval("binding", __FILE__, __LINE__)
|
88
90
|
end
|
89
91
|
|
90
92
|
unless self.class.method_defined?(:__pry__)
|
@@ -124,7 +126,7 @@ class BasicObject
|
|
124
126
|
# BasicObjects don't have respond_to?, so we just define the method
|
125
127
|
# every time. As they also don't have `.freeze`, this call won't
|
126
128
|
# fail as it can for normal Objects.
|
127
|
-
(class << self; self; end).class_eval
|
129
|
+
(class << self; self; end).class_eval(<<-METHOD, __FILE__, __LINE__ + 1)
|
128
130
|
# Get a binding with 'self' set to self, and no locals.
|
129
131
|
#
|
130
132
|
# The default definee is determined by the context in which the
|
@@ -136,7 +138,7 @@ class BasicObject
|
|
136
138
|
def __pry__
|
137
139
|
::Kernel.binding
|
138
140
|
end
|
139
|
-
|
140
|
-
|
141
|
+
METHOD
|
142
|
+
__pry__
|
141
143
|
end
|
142
144
|
end
|
data/lib/pry/editor.rb
CHANGED
@@ -1,11 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'shellwords'
|
4
|
+
|
1
5
|
class Pry
|
2
6
|
class Editor
|
7
|
+
def self.default
|
8
|
+
if (visual = Pry::Env['VISUAL'])
|
9
|
+
return visual
|
10
|
+
end
|
11
|
+
|
12
|
+
if (editor = Pry::Env['EDITOR'])
|
13
|
+
return editor
|
14
|
+
end
|
15
|
+
|
16
|
+
return 'notepad' if Helpers::Platform.windows?
|
17
|
+
|
18
|
+
%w[editor nano vi].find do |editor_exe|
|
19
|
+
Kernel.system("which #{editor_exe} > /dev/null 2>&1")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
3
23
|
include Pry::Helpers::CommandHelpers
|
4
24
|
|
5
|
-
attr_reader :
|
25
|
+
attr_reader :pry_instance
|
6
26
|
|
7
|
-
def initialize(
|
8
|
-
@
|
27
|
+
def initialize(pry_instance)
|
28
|
+
@pry_instance = pry_instance
|
9
29
|
end
|
10
30
|
|
11
31
|
def edit_tempfile_with_content(initial_content, line = 1)
|
@@ -19,7 +39,10 @@ class Pry
|
|
19
39
|
end
|
20
40
|
|
21
41
|
def invoke_editor(file, line, blocking = true)
|
22
|
-
|
42
|
+
unless pry_instance.config.editor
|
43
|
+
raise CommandError,
|
44
|
+
"Please set Pry.config.editor or export $VISUAL or $EDITOR"
|
45
|
+
end
|
23
46
|
|
24
47
|
editor_invocation = build_editor_invocation_string(file, line, blocking)
|
25
48
|
return nil unless editor_invocation
|
@@ -31,40 +54,44 @@ class Pry
|
|
31
54
|
end
|
32
55
|
end
|
33
56
|
|
34
|
-
private
|
35
|
-
|
36
57
|
# Generate the string that's used to start the editor. This includes
|
37
58
|
# all the flags we want as well as the file and line number we
|
38
59
|
# want to open at.
|
39
60
|
def build_editor_invocation_string(file, line, blocking)
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
_pry_.config.editor.call(*args)
|
61
|
+
if pry_instance.config.editor.respond_to?(:call)
|
62
|
+
args = [file, line, blocking][0...(pry_instance.config.editor.arity)]
|
63
|
+
pry_instance.config.editor.call(*args)
|
44
64
|
else
|
45
65
|
sanitized_file = Helpers::Platform.windows? ? file : Shellwords.escape(file)
|
46
|
-
|
66
|
+
editor = pry_instance.config.editor
|
67
|
+
flag = blocking_flag_for_editor(blocking)
|
68
|
+
start_line = start_line_syntax_for_editor(sanitized_file, line)
|
69
|
+
"#{editor} #{flag} #{start_line}"
|
47
70
|
end
|
48
71
|
end
|
49
72
|
|
73
|
+
private
|
74
|
+
|
50
75
|
# Start the editor running, using the calculated invocation string
|
51
76
|
def open_editor(editor_invocation)
|
52
77
|
# Note we dont want to use Pry.config.system here as that
|
53
78
|
# may be invoked non-interactively (i.e via Open4), whereas we want to
|
54
79
|
# ensure the editor is always interactive
|
55
|
-
system(*Shellwords.split(editor_invocation))
|
80
|
+
system(*Shellwords.split(editor_invocation)) ||
|
81
|
+
raise(
|
82
|
+
CommandError,
|
83
|
+
"`#{editor_invocation}` gave exit status: #{$CHILD_STATUS.exitstatus}"
|
84
|
+
)
|
56
85
|
end
|
57
86
|
|
58
87
|
# We need JRuby specific code here cos just shelling out using
|
59
88
|
# system() appears to be pretty broken :/
|
60
89
|
def open_editor_on_jruby(editor_invocation)
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
system(editor_invocation)
|
67
|
-
end
|
90
|
+
require 'spoon'
|
91
|
+
pid = Spoon.spawnp(*Shellwords.split(editor_invocation))
|
92
|
+
Process.waitpid(pid)
|
93
|
+
rescue FFI::NotFoundError
|
94
|
+
system(editor_invocation)
|
68
95
|
end
|
69
96
|
|
70
97
|
# Some editors that run outside the terminal allow you to control whether or
|
@@ -104,7 +131,7 @@ class Pry
|
|
104
131
|
"-l#{line_number} #{file_name}"
|
105
132
|
else
|
106
133
|
if Helpers::Platform.windows?
|
107
|
-
|
134
|
+
file_name.to_s
|
108
135
|
else
|
109
136
|
"+#{line_number} #{file_name}"
|
110
137
|
end
|
@@ -122,7 +149,7 @@ class Pry
|
|
122
149
|
# # => textmate
|
123
150
|
#
|
124
151
|
def editor_name
|
125
|
-
File.basename(
|
152
|
+
File.basename(pry_instance.config.editor).split(" ").first
|
126
153
|
end
|
127
154
|
end
|
128
155
|
end
|
data/lib/pry/env.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Pry
|
4
|
+
# Env is a helper module to work with environment variables.
|
5
|
+
#
|
6
|
+
# @since v0.13.0
|
7
|
+
# @api private
|
8
|
+
module Env
|
9
|
+
def self.[](key)
|
10
|
+
return unless ENV.key?(key)
|
11
|
+
|
12
|
+
value = ENV[key]
|
13
|
+
return if value == ''
|
14
|
+
|
15
|
+
value
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Pry
|
4
|
+
# @api private
|
5
|
+
# @since v0.13.0
|
6
|
+
module ExceptionHandler
|
7
|
+
class << self
|
8
|
+
# Will only show the first line of the backtrace.
|
9
|
+
def handle_exception(output, exception, _pry_instance)
|
10
|
+
if exception.is_a?(UserError) && exception.is_a?(SyntaxError)
|
11
|
+
output.puts "SyntaxError: #{exception.message.sub(/.*syntax error, */m, '')}"
|
12
|
+
else
|
13
|
+
output.puts standard_error_text_for(exception)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def standard_error_text_for(exception)
|
20
|
+
text = exception_text(exception)
|
21
|
+
return text unless exception.respond_to?(:cause)
|
22
|
+
|
23
|
+
cause = exception.cause
|
24
|
+
while cause
|
25
|
+
text += cause_text(cause)
|
26
|
+
cause = cause.cause
|
27
|
+
end
|
28
|
+
|
29
|
+
text
|
30
|
+
end
|
31
|
+
|
32
|
+
def exception_text(exception)
|
33
|
+
"#{exception.class}: #{exception.message}\n" \
|
34
|
+
"from #{exception.backtrace.first}\n"
|
35
|
+
end
|
36
|
+
|
37
|
+
def cause_text(cause)
|
38
|
+
"Caused by #{cause.class}: #{cause}\n" \
|
39
|
+
"from #{cause.backtrace.first}\n"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/pry/exceptions.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
4
|
# As a REPL, we often want to catch any unexpected exceptions that may have
|
3
5
|
# been raised; however we don't want to go overboard and prevent the user
|
@@ -13,7 +15,7 @@ class Pry
|
|
13
15
|
# Don't catch signals (particularly not SIGTERM) as these are unlikely
|
14
16
|
# to be intended for pry itself. We should also make sure that
|
15
17
|
# Kernel#exit works.
|
16
|
-
when *Pry.config.
|
18
|
+
when *Pry.config.unrescued_exceptions
|
17
19
|
false
|
18
20
|
# All other exceptions will be caught.
|
19
21
|
else
|
@@ -23,9 +25,13 @@ class Pry
|
|
23
25
|
end
|
24
26
|
|
25
27
|
# Catches SecurityErrors if $SAFE is set
|
26
|
-
module
|
28
|
+
module TooSafeException
|
27
29
|
def self.===(exception)
|
28
|
-
|
30
|
+
if Pry::HAS_SAFE_LEVEL
|
31
|
+
$SAFE > 0 && exception.is_a?(SecurityError)
|
32
|
+
else
|
33
|
+
exception.is_a?(SecurityError)
|
34
|
+
end
|
29
35
|
end
|
30
36
|
end
|
31
37
|
|
@@ -49,18 +55,14 @@ class Pry
|
|
49
55
|
# the exception is just a vanilla RuntimeError.
|
50
56
|
module FrozenObjectException
|
51
57
|
def self.===(exception)
|
52
|
-
[
|
53
|
-
|
54
|
-
|
58
|
+
[
|
59
|
+
"can't modify frozen class/module",
|
60
|
+
"can't modify frozen Class",
|
61
|
+
"can't modify frozen object"
|
55
62
|
].include?(exception.message)
|
56
63
|
end
|
57
64
|
end
|
58
65
|
|
59
|
-
# Don't catch these exceptions
|
60
|
-
DEFAULT_EXCEPTION_WHITELIST = [SystemExit,
|
61
|
-
SignalException,
|
62
|
-
Pry::TooSafeException]
|
63
|
-
|
64
66
|
# CommandErrors are caught by the REPL loop and displayed to the user. They
|
65
67
|
# indicate an exceptional condition that's fatal to the current command.
|
66
68
|
class CommandError < StandardError; end
|
@@ -68,9 +70,4 @@ class Pry
|
|
68
70
|
|
69
71
|
# indicates obsolete API
|
70
72
|
class ObsoleteError < StandardError; end
|
71
|
-
|
72
|
-
# This is to keep from breaking under Rails 3.2 for people who are doing that
|
73
|
-
# IRB = Pry thing.
|
74
|
-
module ExtendCommandBundle
|
75
|
-
end
|
76
73
|
end
|
data/lib/pry/forwardable.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
4
|
module Forwardable
|
3
5
|
require 'forwardable'
|
@@ -17,7 +19,9 @@ class Pry
|
|
17
19
|
instance_variable_get(target).__send__(private_delegate, *a, &b)
|
18
20
|
end
|
19
21
|
end
|
20
|
-
class_eval
|
22
|
+
class_eval do
|
23
|
+
private(*private_delegates) # rubocop:disable Style/AccessModifierDeclarations
|
24
|
+
end
|
21
25
|
end
|
22
26
|
end
|
23
27
|
end
|