pry 0.10.pre.1-java → 0.10.0.pre2-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +702 -0
- data/LICENSE +2 -2
- data/{README.markdown → README.md} +41 -35
- data/lib/pry.rb +82 -139
- data/lib/pry/cli.rb +77 -30
- data/lib/pry/code.rb +126 -182
- data/lib/pry/code/code_file.rb +103 -0
- data/lib/pry/code/code_range.rb +71 -0
- data/lib/pry/code/loc.rb +92 -0
- data/lib/pry/code_object.rb +172 -0
- data/lib/pry/color_printer.rb +55 -0
- data/lib/pry/command.rb +184 -28
- data/lib/pry/command_set.rb +113 -59
- data/lib/pry/commands.rb +4 -27
- data/lib/pry/commands/amend_line.rb +99 -0
- data/lib/pry/commands/bang.rb +20 -0
- data/lib/pry/commands/bang_pry.rb +17 -0
- data/lib/pry/commands/cat.rb +62 -0
- data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
- data/lib/pry/commands/cat/exception_formatter.rb +77 -0
- data/lib/pry/commands/cat/file_formatter.rb +67 -0
- data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
- data/lib/pry/commands/cd.rb +41 -0
- 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 +165 -0
- data/lib/pry/commands/disable_pry.rb +27 -0
- data/lib/pry/commands/disabled_commands.rb +2 -0
- data/lib/pry/commands/easter_eggs.rb +112 -0
- data/lib/pry/commands/edit.rb +195 -0
- data/lib/pry/commands/edit/exception_patcher.rb +25 -0
- data/lib/pry/commands/edit/file_and_line_locator.rb +36 -0
- data/lib/pry/commands/exit.rb +42 -0
- data/lib/pry/commands/exit_all.rb +29 -0
- data/lib/pry/commands/exit_program.rb +23 -0
- data/lib/pry/commands/find_method.rb +193 -0
- data/lib/pry/commands/fix_indent.rb +19 -0
- data/lib/pry/commands/gem_cd.rb +26 -0
- data/lib/pry/commands/gem_install.rb +32 -0
- data/lib/pry/commands/gem_list.rb +33 -0
- data/lib/pry/commands/gem_open.rb +29 -0
- data/lib/pry/commands/gist.rb +101 -0
- data/lib/pry/commands/help.rb +164 -0
- data/lib/pry/commands/hist.rb +180 -0
- data/lib/pry/commands/import_set.rb +22 -0
- data/lib/pry/commands/install_command.rb +53 -0
- data/lib/pry/commands/jump_to.rb +29 -0
- data/lib/pry/commands/list_inspectors.rb +35 -0
- data/lib/pry/commands/list_prompts.rb +35 -0
- data/lib/pry/commands/ls.rb +114 -0
- 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/nesting.rb +25 -0
- data/lib/pry/commands/play.rb +103 -0
- data/lib/pry/commands/pry_backtrace.rb +25 -0
- data/lib/pry/commands/pry_version.rb +17 -0
- data/lib/pry/commands/raise_up.rb +32 -0
- data/lib/pry/commands/reload_code.rb +62 -0
- data/lib/pry/commands/reset.rb +18 -0
- data/lib/pry/commands/ri.rb +60 -0
- data/lib/pry/commands/save_file.rb +61 -0
- data/lib/pry/commands/shell_command.rb +48 -0
- data/lib/pry/commands/shell_mode.rb +25 -0
- data/lib/pry/commands/show_doc.rb +83 -0
- data/lib/pry/commands/show_info.rb +195 -0
- data/lib/pry/commands/show_input.rb +17 -0
- data/lib/pry/commands/show_source.rb +50 -0
- data/lib/pry/commands/simple_prompt.rb +22 -0
- data/lib/pry/commands/stat.rb +40 -0
- data/lib/pry/commands/switch_to.rb +23 -0
- data/lib/pry/commands/toggle_color.rb +24 -0
- 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 +190 -0
- data/lib/pry/commands/wtf.rb +57 -0
- data/lib/pry/config.rb +20 -229
- 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 +59 -38
- data/lib/pry/editor.rb +133 -0
- data/lib/pry/exceptions.rb +77 -0
- data/lib/pry/helpers.rb +1 -0
- data/lib/pry/helpers/base_helpers.rb +40 -154
- data/lib/pry/helpers/command_helpers.rb +19 -130
- data/lib/pry/helpers/documentation_helpers.rb +21 -11
- data/lib/pry/helpers/table.rb +109 -0
- data/lib/pry/helpers/text.rb +8 -9
- data/lib/pry/history.rb +61 -45
- data/lib/pry/history_array.rb +11 -1
- data/lib/pry/hooks.rb +10 -32
- data/lib/pry/indent.rb +110 -38
- 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 +199 -200
- data/lib/pry/method/disowned.rb +53 -0
- data/lib/pry/method/patcher.rb +125 -0
- data/lib/pry/method/weird_method_locator.rb +186 -0
- data/lib/pry/module_candidate.rb +39 -33
- data/lib/pry/object_path.rb +82 -0
- data/lib/pry/output.rb +50 -0
- data/lib/pry/pager.rb +234 -0
- data/lib/pry/plugins.rb +4 -3
- data/lib/pry/prompt.rb +26 -0
- data/lib/pry/pry_class.rb +199 -227
- data/lib/pry/pry_instance.rb +344 -403
- 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 +82 -0
- data/lib/pry/terminal.rb +79 -0
- data/lib/pry/test/helper.rb +170 -0
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +133 -48
- metadata +132 -197
- data/.document +0 -2
- data/.gemtest +0 -0
- data/.gitignore +0 -16
- data/.travis.yml +0 -17
- data/.yardopts +0 -1
- data/CHANGELOG +0 -387
- data/CONTRIBUTORS +0 -36
- data/Gemfile +0 -2
- data/Rakefile +0 -137
- data/TODO +0 -117
- data/examples/example_basic.rb +0 -15
- data/examples/example_command_override.rb +0 -32
- data/examples/example_commands.rb +0 -36
- data/examples/example_hooks.rb +0 -9
- data/examples/example_image_edit.rb +0 -67
- data/examples/example_input.rb +0 -7
- data/examples/example_input2.rb +0 -29
- data/examples/example_output.rb +0 -11
- data/examples/example_print.rb +0 -6
- data/examples/example_prompt.rb +0 -9
- data/examples/helper.rb +0 -6
- data/lib/pry/completion.rb +0 -221
- data/lib/pry/custom_completions.rb +0 -6
- data/lib/pry/default_commands/cd.rb +0 -81
- data/lib/pry/default_commands/commands.rb +0 -62
- data/lib/pry/default_commands/context.rb +0 -98
- data/lib/pry/default_commands/easter_eggs.rb +0 -95
- data/lib/pry/default_commands/editing.rb +0 -420
- data/lib/pry/default_commands/find_method.rb +0 -169
- data/lib/pry/default_commands/gems.rb +0 -84
- data/lib/pry/default_commands/gist.rb +0 -187
- data/lib/pry/default_commands/help.rb +0 -127
- data/lib/pry/default_commands/hist.rb +0 -120
- data/lib/pry/default_commands/input_and_output.rb +0 -306
- data/lib/pry/default_commands/introspection.rb +0 -410
- data/lib/pry/default_commands/ls.rb +0 -272
- data/lib/pry/default_commands/misc.rb +0 -38
- data/lib/pry/default_commands/navigating_pry.rb +0 -110
- data/lib/pry/default_commands/whereami.rb +0 -92
- data/lib/pry/extended_commands/experimental.rb +0 -7
- 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 -46
- data/test/candidate_helper1.rb +0 -11
- data/test/candidate_helper2.rb +0 -8
- data/test/helper.rb +0 -223
- data/test/test_cli.rb +0 -78
- data/test/test_code.rb +0 -201
- data/test/test_command.rb +0 -712
- data/test/test_command_helpers.rb +0 -9
- data/test/test_command_integration.rb +0 -668
- data/test/test_command_set.rb +0 -610
- data/test/test_completion.rb +0 -62
- data/test/test_control_d_handler.rb +0 -45
- data/test/test_default_commands/example.erb +0 -5
- data/test/test_default_commands/test_cd.rb +0 -318
- data/test/test_default_commands/test_context.rb +0 -280
- data/test/test_default_commands/test_documentation.rb +0 -314
- data/test/test_default_commands/test_find_method.rb +0 -50
- data/test/test_default_commands/test_gems.rb +0 -18
- data/test/test_default_commands/test_help.rb +0 -57
- data/test/test_default_commands/test_input.rb +0 -428
- data/test/test_default_commands/test_introspection.rb +0 -511
- data/test/test_default_commands/test_ls.rb +0 -151
- data/test/test_default_commands/test_shell.rb +0 -343
- data/test/test_default_commands/test_show_source.rb +0 -432
- data/test/test_exception_whitelist.rb +0 -21
- data/test/test_history_array.rb +0 -65
- data/test/test_hooks.rb +0 -521
- data/test/test_indent.rb +0 -277
- data/test/test_input_stack.rb +0 -86
- data/test/test_method.rb +0 -401
- data/test/test_pry.rb +0 -463
- data/test/test_pry_defaults.rb +0 -419
- data/test/test_pry_history.rb +0 -84
- data/test/test_pry_output.rb +0 -41
- data/test/test_sticky_locals.rb +0 -155
- data/test/test_syntax_checking.rb +0 -65
- data/test/test_wrapped_module.rb +0 -174
- data/test/testrc +0 -2
- data/test/testrcbad +0 -2
- data/wiki/Customizing-pry.md +0 -397
- data/wiki/Home.md +0 -4
@@ -0,0 +1,25 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::Edit
|
3
|
+
class ExceptionPatcher
|
4
|
+
attr_accessor :_pry_
|
5
|
+
attr_accessor :state
|
6
|
+
attr_accessor :file_and_line
|
7
|
+
|
8
|
+
def initialize(_pry_, state, exception_file_and_line)
|
9
|
+
@_pry_ = _pry_
|
10
|
+
@state = state
|
11
|
+
@file_and_line = exception_file_and_line
|
12
|
+
end
|
13
|
+
|
14
|
+
# perform the patch
|
15
|
+
def perform_patch
|
16
|
+
file_name, _ = file_and_line
|
17
|
+
lines = state.dynamical_ex_file || File.read(file_name)
|
18
|
+
|
19
|
+
source = Pry::Editor.new(_pry_).edit_tempfile_with_content(lines)
|
20
|
+
_pry_.evaluate_ruby source
|
21
|
+
state.dynamical_ex_file = source.split("\n")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::Edit
|
3
|
+
module FileAndLineLocator
|
4
|
+
class << self
|
5
|
+
def from_binding(target)
|
6
|
+
[target.eval("__FILE__"), target.eval("__LINE__")]
|
7
|
+
end
|
8
|
+
|
9
|
+
def from_code_object(code_object, filename_argument)
|
10
|
+
if File.exists?(code_object.source_file.to_s)
|
11
|
+
[code_object.source_file, code_object.source_line]
|
12
|
+
else
|
13
|
+
raise CommandError, "Cannot find a file for #{filename_argument}!"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def from_exception(exception, backtrace_level)
|
18
|
+
raise CommandError, "No exception found." if exception.nil?
|
19
|
+
|
20
|
+
file_name, line = exception.bt_source_location_for(backtrace_level)
|
21
|
+
raise CommandError, "Exception has no associated file." if file_name.nil?
|
22
|
+
raise CommandError, "Cannot edit exceptions raised in REPL." if Pry.eval_path == file_name
|
23
|
+
|
24
|
+
[file_name, line]
|
25
|
+
end
|
26
|
+
|
27
|
+
# when file and line are passed as a single arg, e.g my_file.rb:30
|
28
|
+
def from_filename_argument(filename_argument)
|
29
|
+
f = File.expand_path(filename_argument)
|
30
|
+
l = f.sub!(/:(\d+)$/, "") ? $1.to_i : 1
|
31
|
+
[f, l]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::Exit < Pry::ClassCommand
|
3
|
+
match 'exit'
|
4
|
+
group 'Navigating Pry'
|
5
|
+
description 'Pop the previous binding.'
|
6
|
+
command_options :keep_retval => true
|
7
|
+
|
8
|
+
banner <<-'BANNER'
|
9
|
+
Usage: exit [OPTIONS] [--help]
|
10
|
+
Aliases: quit
|
11
|
+
|
12
|
+
Pop the previous binding (does NOT exit program). It can be useful to exit a
|
13
|
+
context with a user-provided value. For instance an exit value can be used to
|
14
|
+
determine program flow.
|
15
|
+
|
16
|
+
exit "pry this"
|
17
|
+
exit
|
18
|
+
|
19
|
+
https://github.com/pry/pry/wiki/State-navigation#wiki-Exit_with_value
|
20
|
+
BANNER
|
21
|
+
|
22
|
+
def process
|
23
|
+
if _pry_.binding_stack.one?
|
24
|
+
_pry_.run_command "exit-all #{arg_string}"
|
25
|
+
else
|
26
|
+
# otherwise just pop a binding and return user supplied value
|
27
|
+
process_pop_and_return
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def process_pop_and_return
|
32
|
+
popped_object = _pry_.binding_stack.pop.eval('self')
|
33
|
+
|
34
|
+
# return a user-specified value if given otherwise return the object
|
35
|
+
return target.eval(arg_string) unless arg_string.empty?
|
36
|
+
popped_object
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
Pry::Commands.add_command(Pry::Command::Exit)
|
41
|
+
Pry::Commands.alias_command 'quit', 'exit'
|
42
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::ExitAll < Pry::ClassCommand
|
3
|
+
match 'exit-all'
|
4
|
+
group 'Navigating Pry'
|
5
|
+
description 'End the current Pry session.'
|
6
|
+
|
7
|
+
banner <<-'BANNER'
|
8
|
+
Usage: exit-all [--help]
|
9
|
+
Aliases: !!@
|
10
|
+
|
11
|
+
End the current Pry session (popping all bindings and returning to caller).
|
12
|
+
Accepts optional return value.
|
13
|
+
BANNER
|
14
|
+
|
15
|
+
def process
|
16
|
+
# calculate user-given value
|
17
|
+
exit_value = target.eval(arg_string)
|
18
|
+
|
19
|
+
# clear the binding stack
|
20
|
+
_pry_.binding_stack.clear
|
21
|
+
|
22
|
+
# break out of the repl loop
|
23
|
+
throw(:breakout, exit_value)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
Pry::Commands.add_command(Pry::Command::ExitAll)
|
28
|
+
Pry::Commands.alias_command '!!@', 'exit-all'
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::ExitProgram < Pry::ClassCommand
|
3
|
+
match 'exit-program'
|
4
|
+
group 'Navigating Pry'
|
5
|
+
description 'End the current program.'
|
6
|
+
|
7
|
+
banner <<-'BANNER'
|
8
|
+
Usage: exit-program [--help]
|
9
|
+
Aliases: quit-program
|
10
|
+
!!!
|
11
|
+
|
12
|
+
End the current program.
|
13
|
+
BANNER
|
14
|
+
|
15
|
+
def process
|
16
|
+
Kernel.exit target.eval(arg_string).to_i
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Pry::Commands.add_command(Pry::Command::ExitProgram)
|
21
|
+
Pry::Commands.alias_command 'quit-program', 'exit-program'
|
22
|
+
Pry::Commands.alias_command '!!!', 'exit-program'
|
23
|
+
end
|
@@ -0,0 +1,193 @@
|
|
1
|
+
class Pry
|
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
|
31
|
+
|
32
|
+
def process
|
33
|
+
return if args.size < 1
|
34
|
+
klass = search_class
|
35
|
+
|
36
|
+
matches = if opts.content?
|
37
|
+
content_search(klass)
|
38
|
+
else
|
39
|
+
name_search(klass)
|
40
|
+
end
|
41
|
+
|
42
|
+
show_search_results(matches)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
# @return [Regexp] The pattern to search for.
|
48
|
+
def pattern
|
49
|
+
@pattern ||= ::Regexp.new args[0]
|
50
|
+
end
|
51
|
+
|
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 text.bold("No Methods Matched")
|
58
|
+
else
|
59
|
+
print_matches(matches)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
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
|
75
|
+
end
|
76
|
+
|
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
|
87
|
+
end
|
88
|
+
|
89
|
+
# Print matched methods for a class
|
90
|
+
def print_matches_for_class(klass, grouped)
|
91
|
+
output.puts text.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
|
97
|
+
|
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))
|
103
|
+
else
|
104
|
+
""
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def matched_method_lines(header, method)
|
109
|
+
method.source.split(/\n/).select {|x| x =~ pattern }.join("\n#{' ' * header.length}")
|
110
|
+
end
|
111
|
+
|
112
|
+
# Run the given block against every constant in the provided namespace.
|
113
|
+
#
|
114
|
+
# @param [Module] klass The namespace in which to start the search.
|
115
|
+
# @param [Hash<Module,Boolean>] done The namespaces we've already visited (private)
|
116
|
+
# @yieldparam klass Each class/module in the namespace.
|
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.
|
134
|
+
else
|
135
|
+
recurse_namespace(const, done, &block)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
# Gather all the methods in a namespace that pass the given block.
|
141
|
+
#
|
142
|
+
# @param [Module] namespace The namespace in which to search.
|
143
|
+
# @yieldparam [Method] method The method to test
|
144
|
+
# @yieldreturn [Boolean]
|
145
|
+
# @return [Array<Method>]
|
146
|
+
#
|
147
|
+
def search_all_methods(namespace)
|
148
|
+
done = Hash.new{ |h,k| h[k] = {} }
|
149
|
+
matches = []
|
150
|
+
|
151
|
+
recurse_namespace(namespace) do |klass|
|
152
|
+
(Pry::Method.all_from_class(klass) + Pry::Method.all_from_obj(klass)).each do |method|
|
153
|
+
next if done[method.owner][method.name]
|
154
|
+
done[method.owner][method.name] = true
|
155
|
+
|
156
|
+
matches << method if yield method
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
matches
|
161
|
+
end
|
162
|
+
|
163
|
+
# Search for all methods with a name that matches the given regex
|
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
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
# Search for all methods who's implementation matches the given regex
|
176
|
+
# within a namespace.
|
177
|
+
#
|
178
|
+
# @param [Module] namespace The namespace to search
|
179
|
+
# @return [Array<Method>]
|
180
|
+
#
|
181
|
+
def content_search(namespace)
|
182
|
+
search_all_methods(namespace) do |meth|
|
183
|
+
begin
|
184
|
+
meth.source =~ pattern
|
185
|
+
rescue RescuableException
|
186
|
+
false
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
Pry::Commands.add_command(Pry::Command::FindMethod)
|
193
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::FixIndent < Pry::ClassCommand
|
3
|
+
match 'fix-indent'
|
4
|
+
group 'Input and Output'
|
5
|
+
|
6
|
+
description "Correct the indentation for contents of the input buffer"
|
7
|
+
|
8
|
+
banner <<-USAGE
|
9
|
+
Usage: fix-indent
|
10
|
+
USAGE
|
11
|
+
|
12
|
+
def process
|
13
|
+
indented_str = Pry::Indent.indent(eval_string)
|
14
|
+
eval_string.replace indented_str
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
Pry::Commands.add_command(Pry::Command::FixIndent)
|
19
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::GemCd < Pry::ClassCommand
|
3
|
+
match 'gem-cd'
|
4
|
+
group 'Gems'
|
5
|
+
description "Change working directory to specified gem's directory."
|
6
|
+
command_options :argument_required => true
|
7
|
+
|
8
|
+
banner <<-'BANNER'
|
9
|
+
Usage: gem-cd GEM_NAME
|
10
|
+
|
11
|
+
Change the current working directory to that in which the given gem is
|
12
|
+
installed.
|
13
|
+
BANNER
|
14
|
+
|
15
|
+
def process(gem)
|
16
|
+
Dir.chdir(Rubygem.spec(gem).full_gem_path)
|
17
|
+
output.puts(Dir.pwd)
|
18
|
+
end
|
19
|
+
|
20
|
+
def complete(str)
|
21
|
+
Rubygem.complete(str)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
Pry::Commands.add_command(Pry::Command::GemCd)
|
26
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::GemInstall < Pry::ClassCommand
|
3
|
+
match 'gem-install'
|
4
|
+
group 'Gems'
|
5
|
+
description 'Install a gem and refresh the gem cache.'
|
6
|
+
command_options :argument_required => true
|
7
|
+
|
8
|
+
banner <<-'BANNER'
|
9
|
+
Usage: gem-install GEM_NAME
|
10
|
+
|
11
|
+
Installs the given gem, refreshes the gem cache, and requires the gem for you
|
12
|
+
based on a best guess from the gem name.
|
13
|
+
|
14
|
+
gem-install pry-stack_explorer
|
15
|
+
BANNER
|
16
|
+
|
17
|
+
def setup
|
18
|
+
require 'rubygems/dependency_installer' unless defined? Gem::DependencyInstaller
|
19
|
+
end
|
20
|
+
|
21
|
+
def process(gem)
|
22
|
+
Rubygem.install(gem)
|
23
|
+
output.puts "Gem `#{ text.green(gem) }` installed."
|
24
|
+
require gem
|
25
|
+
rescue LoadError
|
26
|
+
require_path = gem.split('-').join('/')
|
27
|
+
require require_path
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Pry::Commands.add_command(Pry::Command::GemInstall)
|
32
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::GemList < Pry::ClassCommand
|
3
|
+
match 'gem-list'
|
4
|
+
group 'Gems'
|
5
|
+
description 'List and search installed gems.'
|
6
|
+
|
7
|
+
banner <<-'BANNER'
|
8
|
+
Usage: gem-list [REGEX]
|
9
|
+
|
10
|
+
List all installed gems, when a regex is provided, limit the output to those
|
11
|
+
that match the regex.
|
12
|
+
BANNER
|
13
|
+
|
14
|
+
def process(pattern = nil)
|
15
|
+
pattern = Regexp.compile(pattern || '')
|
16
|
+
gems = Rubygem.list(pattern).group_by(&:name)
|
17
|
+
|
18
|
+
gems.each do |gem, specs|
|
19
|
+
specs.sort! do |a,b|
|
20
|
+
Gem::Version.new(b.version) <=> Gem::Version.new(a.version)
|
21
|
+
end
|
22
|
+
|
23
|
+
versions = specs.each_with_index.map do |spec, index|
|
24
|
+
index == 0 ? text.bright_green(spec.version.to_s) : text.green(spec.version.to_s)
|
25
|
+
end
|
26
|
+
|
27
|
+
output.puts "#{text.default gem} (#{versions.join ', '})"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
Pry::Commands.add_command(Pry::Command::GemList)
|
33
|
+
end
|