pry 0.10.3 → 0.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +439 -16
- data/LICENSE +1 -1
- data/README.md +362 -302
- data/bin/pry +4 -7
- data/lib/pry/basic_object.rb +10 -0
- data/lib/pry/block_command.rb +22 -0
- data/lib/pry/class_command.rb +194 -0
- data/lib/pry/cli.rb +84 -97
- data/lib/pry/code/code_file.rb +37 -26
- data/lib/pry/code/code_range.rb +7 -5
- data/lib/pry/code/loc.rb +26 -13
- data/lib/pry/code.rb +42 -31
- data/lib/pry/code_object.rb +53 -28
- data/lib/pry/color_printer.rb +46 -35
- data/lib/pry/command.rb +197 -369
- data/lib/pry/command_set.rb +89 -114
- data/lib/pry/command_state.rb +31 -0
- data/lib/pry/commands/amend_line.rb +86 -82
- 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 +85 -72
- data/lib/pry/commands/cat/file_formatter.rb +56 -46
- data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
- data/lib/pry/commands/cat.rb +62 -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 +48 -23
- data/lib/pry/commands/clear_screen.rb +20 -0
- data/lib/pry/commands/code_collector.rb +148 -131
- data/lib/pry/commands/disable_pry.rb +23 -19
- data/lib/pry/commands/easter_eggs.rb +23 -34
- 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 +185 -157
- data/lib/pry/commands/exit.rb +40 -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 -162
- data/lib/pry/commands/fix_indent.rb +16 -12
- data/lib/pry/commands/help.rb +140 -133
- data/lib/pry/commands/hist.rb +151 -149
- data/lib/pry/commands/import_set.rb +20 -15
- 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 -31
- data/lib/pry/commands/ls/formatter.rb +42 -36
- data/lib/pry/commands/ls/globals.rb +38 -36
- data/lib/pry/commands/ls/grep.rb +17 -15
- data/lib/pry/commands/ls/instance_vars.rb +29 -28
- 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 -24
- data/lib/pry/commands/ls/local_vars.rb +38 -30
- data/lib/pry/commands/ls/ls_entity.rb +47 -52
- data/lib/pry/commands/ls/methods.rb +49 -51
- data/lib/pry/commands/ls/methods_helper.rb +46 -42
- data/lib/pry/commands/ls/self_methods.rb +23 -21
- data/lib/pry/commands/ls.rb +124 -103
- data/lib/pry/commands/nesting.rb +21 -17
- data/lib/pry/commands/play.rb +92 -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 +33 -27
- data/lib/pry/commands/reload_code.rb +60 -48
- data/lib/pry/commands/reset.rb +16 -12
- data/lib/pry/commands/ri.rb +57 -42
- data/lib/pry/commands/save_file.rb +45 -43
- data/lib/pry/commands/shell_command.rb +56 -29
- data/lib/pry/commands/shell_mode.rb +22 -18
- data/lib/pry/commands/show_doc.rb +80 -70
- data/lib/pry/commands/show_info.rb +194 -155
- data/lib/pry/commands/show_input.rb +16 -11
- data/lib/pry/commands/show_source.rb +110 -42
- 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 -84
- data/lib/pry/commands/whereami.rb +156 -141
- data/lib/pry/commands/wtf.rb +78 -40
- 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 +310 -20
- data/lib/pry/control_d_handler.rb +28 -0
- data/lib/pry/core_extensions.rb +22 -9
- data/lib/pry/editor.rb +56 -34
- data/lib/pry/env.rb +18 -0
- data/lib/pry/exception_handler.rb +43 -0
- data/lib/pry/exceptions.rb +13 -18
- data/lib/pry/forwardable.rb +27 -0
- data/lib/pry/helpers/base_helpers.rb +20 -62
- data/lib/pry/helpers/command_helpers.rb +52 -62
- data/lib/pry/helpers/documentation_helpers.rb +21 -12
- data/lib/pry/helpers/options_helpers.rb +15 -8
- data/lib/pry/helpers/platform.rb +55 -0
- data/lib/pry/helpers/table.rb +44 -32
- data/lib/pry/helpers/text.rb +96 -85
- data/lib/pry/helpers.rb +3 -0
- data/lib/pry/history.rb +81 -55
- data/lib/pry/hooks.rb +60 -110
- data/lib/pry/indent.rb +74 -68
- data/lib/pry/input_completer.rb +199 -158
- data/lib/pry/input_lock.rb +7 -10
- data/lib/pry/inspector.rb +36 -24
- data/lib/pry/last_exception.rb +45 -45
- data/lib/pry/method/disowned.rb +19 -5
- data/lib/pry/method/patcher.rb +14 -8
- data/lib/pry/method/weird_method_locator.rb +79 -45
- data/lib/pry/method.rb +178 -124
- data/lib/pry/object_path.rb +37 -28
- data/lib/pry/output.rb +102 -16
- data/lib/pry/pager.rb +187 -174
- data/lib/pry/prompt.rb +213 -25
- data/lib/pry/pry_class.rb +119 -98
- data/lib/pry/pry_instance.rb +261 -224
- data/lib/pry/repl.rb +83 -29
- data/lib/pry/repl_file_loader.rb +27 -22
- data/lib/pry/ring.rb +89 -0
- data/lib/pry/slop/LICENSE +20 -0
- data/lib/pry/slop/commands.rb +190 -0
- data/lib/pry/slop/option.rb +210 -0
- data/lib/pry/slop.rb +672 -0
- data/lib/pry/syntax_highlighter.rb +26 -0
- data/lib/pry/system_command_handler.rb +17 -0
- data/lib/pry/testable/evalable.rb +24 -0
- data/lib/pry/testable/mockable.rb +22 -0
- data/lib/pry/testable/pry_tester.rb +88 -0
- data/lib/pry/testable/utility.rb +34 -0
- data/lib/pry/testable/variables.rb +52 -0
- data/lib/pry/testable.rb +68 -0
- data/lib/pry/version.rb +3 -1
- data/lib/pry/warning.rb +20 -0
- data/lib/pry/{module_candidate.rb → wrapped_module/candidate.rb} +35 -32
- data/lib/pry/wrapped_module.rb +68 -63
- data/lib/pry.rb +133 -149
- metadata +58 -69
- 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/gist.rb +0 -101
- data/lib/pry/commands/install_command.rb +0 -53
- data/lib/pry/commands/list_prompts.rb +0 -35
- data/lib/pry/commands/simple_prompt.rb +0 -22
- data/lib/pry/commands.rb +0 -6
- data/lib/pry/config/behavior.rb +0 -139
- data/lib/pry/config/convenience.rb +0 -25
- data/lib/pry/config/default.rb +0 -161
- data/lib/pry/history_array.rb +0 -121
- data/lib/pry/plugins.rb +0 -103
- data/lib/pry/rbx_path.rb +0 -22
- data/lib/pry/rubygem.rb +0 -82
- data/lib/pry/terminal.rb +0 -79
- data/lib/pry/test/helper.rb +0 -170
@@ -1,193 +1,199 @@
|
|
1
|
-
|
2
|
-
class Command::FindMethod < Pry::ClassCommand
|
3
|
-
extend Pry::Helpers::BaseHelpers
|
4
|
-
|
5
|
-
match 'find-method'
|
6
|
-
group 'Context'
|
7
|
-
description 'Recursively search for a method within a Class/Module or the current namespace.'
|
8
|
-
command_options :shellwords => false
|
9
|
-
|
10
|
-
banner <<-'BANNER'
|
11
|
-
Usage: find-method [-n|-c] METHOD [NAMESPACE]
|
12
|
-
|
13
|
-
Recursively search for a method within a Class/Module or the current namespace.
|
14
|
-
Use the `-n` switch (the default) to search for methods whose name matches the
|
15
|
-
given regex. Use the `-c` switch to search for methods that contain the given
|
16
|
-
code.
|
17
|
-
|
18
|
-
# Find all methods whose name match /re/ inside
|
19
|
-
# the Pry namespace. Matches Pry#repl, etc.
|
20
|
-
find-method re Pry
|
21
|
-
|
22
|
-
# Find all methods that contain the code:
|
23
|
-
# output.puts inside the Pry namepsace.
|
24
|
-
find-method -c 'output.puts' Pry
|
25
|
-
BANNER
|
26
|
-
|
27
|
-
def options(opt)
|
28
|
-
opt.on :n, :name, "Search for a method by name"
|
29
|
-
opt.on :c, :content, "Search for a method based on content in Regex form"
|
30
|
-
end
|
1
|
+
# frozen_string_literal: true
|
31
2
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
3
|
+
class Pry
|
4
|
+
class Command
|
5
|
+
class FindMethod < Pry::ClassCommand
|
6
|
+
extend Pry::Helpers::BaseHelpers
|
7
|
+
|
8
|
+
match 'find-method'
|
9
|
+
group 'Context'
|
10
|
+
description 'Recursively search for a method within a Class/Module or ' \
|
11
|
+
'the current namespace.'
|
12
|
+
command_options shellwords: false
|
13
|
+
|
14
|
+
banner <<-'BANNER'
|
15
|
+
Usage: find-method [-n|-c] METHOD [NAMESPACE]
|
16
|
+
|
17
|
+
Recursively search for a method within a Class/Module or the current namespace.
|
18
|
+
Use the `-n` switch (the default) to search for methods whose name matches the
|
19
|
+
given regex. Use the `-c` switch to search for methods that contain the given
|
20
|
+
code.
|
21
|
+
|
22
|
+
# Find all methods whose name match /re/ inside
|
23
|
+
# the Pry namespace. Matches Pry#repl, etc.
|
24
|
+
find-method re Pry
|
25
|
+
|
26
|
+
# Find all methods that contain the code:
|
27
|
+
# output.puts inside the Pry namespace.
|
28
|
+
find-method -c 'output.puts' Pry
|
29
|
+
BANNER
|
30
|
+
|
31
|
+
def options(opt)
|
32
|
+
opt.on :n, :name, "Search for a method by name"
|
33
|
+
opt.on :c, :content, "Search for a method based on content in Regex form"
|
40
34
|
end
|
41
35
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
private
|
36
|
+
def process
|
37
|
+
return if args.empty?
|
46
38
|
|
47
|
-
|
48
|
-
def pattern
|
49
|
-
@pattern ||= ::Regexp.new args[0]
|
50
|
-
end
|
39
|
+
klass = search_class
|
51
40
|
|
52
|
-
|
53
|
-
|
54
|
-
# @param [Array] matches
|
55
|
-
def show_search_results(matches)
|
56
|
-
if matches.empty?
|
57
|
-
output.puts text.bold("No Methods Matched")
|
58
|
-
else
|
59
|
-
print_matches(matches)
|
41
|
+
matches = opts.content? ? content_search(klass) : name_search(klass)
|
42
|
+
show_search_results(matches)
|
60
43
|
end
|
61
|
-
end
|
62
44
|
|
63
|
-
|
64
|
-
# We only search classes, so if the search object is an
|
65
|
-
# instance, return its class. If no search object is given
|
66
|
-
# search `target_self`.
|
67
|
-
def search_class
|
68
|
-
klass = if args[1]
|
69
|
-
target.eval(args[1])
|
70
|
-
else
|
71
|
-
target_self
|
72
|
-
end
|
73
|
-
|
74
|
-
klass.is_a?(Module) ? klass : klass.class
|
75
|
-
end
|
45
|
+
private
|
76
46
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
grouped = matches.group_by(&:owner)
|
82
|
-
order = grouped.keys.sort_by{ |x| x.name || x.to_s }
|
47
|
+
# @return [Regexp] The pattern to search for.
|
48
|
+
def pattern
|
49
|
+
@pattern ||= ::Regexp.new args[0]
|
50
|
+
end
|
83
51
|
|
84
|
-
|
85
|
-
|
52
|
+
# Output the result of the search.
|
53
|
+
#
|
54
|
+
# @param [Array] matches
|
55
|
+
def show_search_results(matches)
|
56
|
+
if matches.empty?
|
57
|
+
output.puts bold("No Methods Matched")
|
58
|
+
else
|
59
|
+
print_matches(matches)
|
60
|
+
end
|
86
61
|
end
|
87
|
-
end
|
88
62
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
63
|
+
# The class to search for methods.
|
64
|
+
# We only search classes, so if the search object is an
|
65
|
+
# instance, return its class. If no search object is given
|
66
|
+
# search `target_self`.
|
67
|
+
def search_class
|
68
|
+
klass = if args[1]
|
69
|
+
target.eval(args[1])
|
70
|
+
else
|
71
|
+
target_self
|
72
|
+
end
|
73
|
+
|
74
|
+
klass.is_a?(Module) ? klass : klass.class
|
95
75
|
end
|
96
|
-
end
|
97
76
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
77
|
+
# pretty-print a list of matching methods.
|
78
|
+
#
|
79
|
+
# @param [Array<Method>] matches
|
80
|
+
def print_matches(matches)
|
81
|
+
grouped = matches.group_by(&:owner)
|
82
|
+
order = grouped.keys.sort_by { |x| x.name || x.to_s }
|
83
|
+
|
84
|
+
order.each do |klass|
|
85
|
+
print_matches_for_class(klass, grouped)
|
86
|
+
end
|
105
87
|
end
|
106
|
-
end
|
107
88
|
|
108
|
-
|
109
|
-
|
110
|
-
|
89
|
+
# Print matched methods for a class
|
90
|
+
def print_matches_for_class(klass, grouped)
|
91
|
+
output.puts bold(klass.name)
|
92
|
+
grouped[klass].each do |method|
|
93
|
+
header = method.name_with_owner
|
94
|
+
output.puts header + additional_info(header, method)
|
95
|
+
end
|
96
|
+
end
|
111
97
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
#
|
118
|
-
def recurse_namespace(klass, done={}, &block)
|
119
|
-
return if !(Module === klass) || done[klass]
|
120
|
-
|
121
|
-
done[klass] = true
|
122
|
-
|
123
|
-
yield klass
|
124
|
-
|
125
|
-
klass.constants.each do |name|
|
126
|
-
next if klass.autoload?(name)
|
127
|
-
begin
|
128
|
-
const = klass.const_get(name)
|
129
|
-
rescue RescuableException
|
130
|
-
# constant loading is an inexact science at the best of times,
|
131
|
-
# this often happens when a constant was .autoload? but someone
|
132
|
-
# tried to load it. It's now not .autoload? but will still raise
|
133
|
-
# a NameError when you access it.
|
98
|
+
# Return the matched lines of method source if `-c` is given or ""
|
99
|
+
# if `-c` was not given
|
100
|
+
def additional_info(header, method)
|
101
|
+
if opts.content?
|
102
|
+
': ' + colorize_code(matched_method_lines(header, method))
|
134
103
|
else
|
135
|
-
|
104
|
+
""
|
136
105
|
end
|
137
106
|
end
|
138
|
-
end
|
139
107
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
108
|
+
def matched_method_lines(header, method)
|
109
|
+
method.source.split(/\n/).select { |x| x =~ pattern }.join(
|
110
|
+
"\n#{' ' * header.length}"
|
111
|
+
)
|
112
|
+
end
|
113
|
+
|
114
|
+
# Run the given block against every constant in the provided namespace.
|
115
|
+
#
|
116
|
+
# @param [Module] klass The namespace in which to start the search.
|
117
|
+
# @param [Hash<Module,Boolean>] done The namespaces we've already visited (private)
|
118
|
+
# @yieldparam klass Each class/module in the namespace.
|
119
|
+
#
|
120
|
+
def recurse_namespace(klass, done = {}, &block)
|
121
|
+
return if !klass.is_a?(Module) || done[klass]
|
122
|
+
|
123
|
+
done[klass] = true
|
124
|
+
|
125
|
+
yield klass
|
126
|
+
|
127
|
+
klass.constants.each do |name|
|
128
|
+
next if klass.autoload?(name)
|
129
|
+
|
130
|
+
begin
|
131
|
+
const = klass.const_get(name)
|
132
|
+
rescue RescuableException # rubocop:disable Lint/HandleExceptions
|
133
|
+
# constant loading is an inexact science at the best of times,
|
134
|
+
# this often happens when a constant was .autoload? but someone
|
135
|
+
# tried to load it. It's now not .autoload? but will still raise
|
136
|
+
# a NameError when you access it.
|
137
|
+
else
|
138
|
+
recurse_namespace(const, done, &block)
|
139
|
+
end
|
157
140
|
end
|
158
141
|
end
|
159
142
|
|
160
|
-
|
161
|
-
|
143
|
+
# Gather all the methods in a namespace that pass the given block.
|
144
|
+
#
|
145
|
+
# @param [Module] namespace The namespace in which to search.
|
146
|
+
# @yieldparam [Method] method The method to test
|
147
|
+
# @yieldreturn [Boolean]
|
148
|
+
# @return [Array<Method>]
|
149
|
+
#
|
150
|
+
def search_all_methods(namespace)
|
151
|
+
done = Hash.new { |h, k| h[k] = {} }
|
152
|
+
matches = []
|
153
|
+
|
154
|
+
recurse_namespace(namespace) do |klass|
|
155
|
+
methods = Pry::Method.all_from_class(klass) + Pry::Method.all_from_obj(klass)
|
156
|
+
methods.each do |method|
|
157
|
+
next if done[method.owner][method.name]
|
158
|
+
|
159
|
+
done[method.owner][method.name] = true
|
160
|
+
|
161
|
+
matches << method if yield method
|
162
|
+
end
|
163
|
+
end
|
162
164
|
|
163
|
-
|
164
|
-
# within a namespace.
|
165
|
-
#
|
166
|
-
# @param [Module] namespace The namespace to search
|
167
|
-
# @return [Array<Method>]
|
168
|
-
#
|
169
|
-
def name_search(namespace)
|
170
|
-
search_all_methods(namespace) do |meth|
|
171
|
-
meth.name =~ pattern
|
165
|
+
matches
|
172
166
|
end
|
173
|
-
end
|
174
167
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
168
|
+
# Search for all methods with a name that matches the given regex
|
169
|
+
# within a namespace.
|
170
|
+
#
|
171
|
+
# @param [Module] namespace The namespace to search
|
172
|
+
# @return [Array<Method>]
|
173
|
+
#
|
174
|
+
def name_search(namespace)
|
175
|
+
search_all_methods(namespace) do |meth|
|
176
|
+
meth.name =~ pattern
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
# Search for all methods who's implementation matches the given regex
|
181
|
+
# within a namespace.
|
182
|
+
#
|
183
|
+
# @param [Module] namespace The namespace to search
|
184
|
+
# @return [Array<Method>]
|
185
|
+
#
|
186
|
+
def content_search(namespace)
|
187
|
+
search_all_methods(namespace) do |meth|
|
188
|
+
begin
|
189
|
+
meth.source =~ pattern
|
190
|
+
rescue RescuableException
|
191
|
+
false
|
192
|
+
end
|
187
193
|
end
|
188
194
|
end
|
189
195
|
end
|
190
|
-
end
|
191
196
|
|
192
|
-
|
197
|
+
Pry::Commands.add_command(Pry::Command::FindMethod)
|
198
|
+
end
|
193
199
|
end
|
@@ -1,19 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
|
-
class Command
|
3
|
-
|
4
|
-
|
4
|
+
class Command
|
5
|
+
class FixIndent < Pry::ClassCommand
|
6
|
+
match 'fix-indent'
|
7
|
+
group 'Input and Output'
|
5
8
|
|
6
|
-
|
9
|
+
description "Correct the indentation for contents of the input buffer"
|
7
10
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
+
banner <<-USAGE
|
12
|
+
Usage: fix-indent
|
13
|
+
USAGE
|
11
14
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
+
def process
|
16
|
+
indented_str = Pry::Indent.indent(eval_string)
|
17
|
+
pry_instance.eval_string = indented_str
|
18
|
+
end
|
15
19
|
end
|
16
|
-
end
|
17
20
|
|
18
|
-
|
21
|
+
Pry::Commands.add_command(Pry::Command::FixIndent)
|
22
|
+
end
|
19
23
|
end
|