pry 0.10.pre.1-i386-mingw32 → 0.10.0.pre3-i386-mingw32
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 +122 -183
- 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,22 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::ImportSet < Pry::ClassCommand
|
3
|
+
match 'import-set'
|
4
|
+
group 'Commands'
|
5
|
+
# TODO: Provide a better description with examples and a general conception
|
6
|
+
# of this command.
|
7
|
+
description 'Import a Pry command set.'
|
8
|
+
|
9
|
+
banner <<-'BANNER'
|
10
|
+
Import a Pry command set.
|
11
|
+
BANNER
|
12
|
+
|
13
|
+
def process(command_set_name)
|
14
|
+
raise CommandError, "Provide a command set name" if command_set.nil?
|
15
|
+
|
16
|
+
set = target.eval(arg_string)
|
17
|
+
_pry_.commands.import set
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Pry::Commands.add_command(Pry::Command::ImportSet)
|
22
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::InstallCommand < Pry::ClassCommand
|
3
|
+
match 'install-command'
|
4
|
+
group 'Commands'
|
5
|
+
description 'Install a disabled command.'
|
6
|
+
|
7
|
+
banner <<-'BANNER'
|
8
|
+
Usage: install-command COMMAND
|
9
|
+
|
10
|
+
Installs the gems necessary to run the given COMMAND. You will generally not
|
11
|
+
need to run this unless told to by an error message.
|
12
|
+
BANNER
|
13
|
+
|
14
|
+
def process(name)
|
15
|
+
require 'rubygems/dependency_installer' unless defined? Gem::DependencyInstaller
|
16
|
+
command = find_command(name)
|
17
|
+
|
18
|
+
unless command
|
19
|
+
output.puts "Command #{ text.green(name) } is not found"
|
20
|
+
return
|
21
|
+
end
|
22
|
+
|
23
|
+
if command_dependencies_met?(command.options)
|
24
|
+
output.puts "Dependencies for #{ text.green(name) } are met. Nothing to do"
|
25
|
+
return
|
26
|
+
end
|
27
|
+
|
28
|
+
output.puts "Attempting to install #{ text.green(name) } command..."
|
29
|
+
gems_to_install = Array(command.options[:requires_gem])
|
30
|
+
|
31
|
+
gems_to_install.each do |g|
|
32
|
+
next if Rubygem.installed?(g)
|
33
|
+
output.puts "Installing #{ text.green(g) } gem..."
|
34
|
+
Rubygem.install(g)
|
35
|
+
end
|
36
|
+
|
37
|
+
gems_to_install.each do |g|
|
38
|
+
begin
|
39
|
+
require g
|
40
|
+
rescue LoadError
|
41
|
+
fail_msg = "Required gem #{ text.green(g) } installed but not found."
|
42
|
+
fail_msg += " Aborting command installation\n"
|
43
|
+
fail_msg += 'Tips: 1. Check your PATH; 2. Run `bundle update`'
|
44
|
+
raise CommandError, fail_msg
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
output.puts "Installation of #{ text.green(name) } successful! Type `help #{name}` for information"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
Pry::Commands.add_command(Pry::Command::InstallCommand)
|
53
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::JumpTo < Pry::ClassCommand
|
3
|
+
match 'jump-to'
|
4
|
+
group 'Navigating Pry'
|
5
|
+
description 'Jump to a binding further up the stack.'
|
6
|
+
|
7
|
+
banner <<-'BANNER'
|
8
|
+
Jump to a binding further up the stack, popping all bindings below.
|
9
|
+
BANNER
|
10
|
+
|
11
|
+
def process(break_level)
|
12
|
+
break_level = break_level.to_i
|
13
|
+
nesting_level = _pry_.binding_stack.size - 1
|
14
|
+
|
15
|
+
case break_level
|
16
|
+
when nesting_level
|
17
|
+
output.puts "Already at nesting level #{nesting_level}"
|
18
|
+
when (0...nesting_level)
|
19
|
+
_pry_.binding_stack.slice!(break_level + 1, _pry_.binding_stack.size)
|
20
|
+
|
21
|
+
else
|
22
|
+
max_nest_level = nesting_level - 1
|
23
|
+
output.puts "Invalid nest level. Must be between 0 and #{max_nest_level}. Got #{break_level}."
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Pry::Commands.add_command(Pry::Command::JumpTo)
|
29
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class Pry::Command::ListInspectors < Pry::ClassCommand
|
2
|
+
match 'list-inspectors'
|
3
|
+
group 'Input and Output'
|
4
|
+
description 'List the inspector procs available for use.'
|
5
|
+
banner <<-BANNER
|
6
|
+
Usage: list-inspectors
|
7
|
+
|
8
|
+
List the inspector procs available to print return values. You can use
|
9
|
+
change-inspector to switch between them.
|
10
|
+
BANNER
|
11
|
+
|
12
|
+
def process
|
13
|
+
output.puts heading("Available inspectors") + "\n"
|
14
|
+
inspector_map.each do |name, inspector|
|
15
|
+
output.write "Name: #{text.bold(name)}"
|
16
|
+
output.puts selected_inspector?(inspector) ? selected_text : ""
|
17
|
+
output.puts inspector[:description]
|
18
|
+
output.puts
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def inspector_map
|
24
|
+
Pry::Inspector::MAP
|
25
|
+
end
|
26
|
+
|
27
|
+
def selected_text
|
28
|
+
text.red " (selected) "
|
29
|
+
end
|
30
|
+
|
31
|
+
def selected_inspector?(inspector)
|
32
|
+
_pry_.print == inspector[:value]
|
33
|
+
end
|
34
|
+
Pry::Commands.add_command(self)
|
35
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class Pry::Command::ListPrompts < Pry::ClassCommand
|
2
|
+
match 'list-prompts'
|
3
|
+
group 'Input and Output'
|
4
|
+
description 'List the prompts available for use.'
|
5
|
+
banner <<-BANNER
|
6
|
+
Usage: list-prompts
|
7
|
+
|
8
|
+
List the available prompts. You can use change-prompt to switch between
|
9
|
+
them.
|
10
|
+
BANNER
|
11
|
+
|
12
|
+
def process
|
13
|
+
output.puts heading("Available prompts") + "\n"
|
14
|
+
prompt_map.each do |name, prompt|
|
15
|
+
output.write "Name: #{text.bold(name)}"
|
16
|
+
output.puts selected_prompt?(prompt) ? selected_text : ""
|
17
|
+
output.puts prompt[:description]
|
18
|
+
output.puts
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def prompt_map
|
24
|
+
Pry::Prompt::MAP
|
25
|
+
end
|
26
|
+
|
27
|
+
def selected_text
|
28
|
+
text.red " (selected) "
|
29
|
+
end
|
30
|
+
|
31
|
+
def selected_prompt?(prompt)
|
32
|
+
_pry_.prompt == prompt[:value]
|
33
|
+
end
|
34
|
+
Pry::Commands.add_command(self)
|
35
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'pry/commands/ls/ls_entity'
|
2
|
+
class Pry
|
3
|
+
class Command::Ls < Pry::ClassCommand
|
4
|
+
DEFAULT_OPTIONS = {
|
5
|
+
:heading_color => :bright_blue,
|
6
|
+
:public_method_color => :default,
|
7
|
+
:private_method_color => :blue,
|
8
|
+
:protected_method_color => :blue,
|
9
|
+
:method_missing_color => :bright_red,
|
10
|
+
:local_var_color => :yellow,
|
11
|
+
:pry_var_color => :default, # e.g. _, _pry_, _file_
|
12
|
+
:instance_var_color => :blue, # e.g. @foo
|
13
|
+
:class_var_color => :bright_blue, # e.g. @@foo
|
14
|
+
:global_var_color => :default, # e.g. $CODERAY_DEBUG, $eventmachine_library
|
15
|
+
:builtin_global_color => :cyan, # e.g. $stdin, $-w, $PID
|
16
|
+
:pseudo_global_color => :cyan, # e.g. $~, $1..$9, $LAST_MATCH_INFO
|
17
|
+
:constant_color => :default, # e.g. VERSION, ARGF
|
18
|
+
:class_constant_color => :blue, # e.g. Object, Kernel
|
19
|
+
:exception_constant_color => :magenta, # e.g. Exception, RuntimeError
|
20
|
+
:unloaded_constant_color => :yellow, # Any constant that is still in .autoload? state
|
21
|
+
:separator => " ",
|
22
|
+
:ceiling => [Object, Module, Class]
|
23
|
+
}
|
24
|
+
|
25
|
+
|
26
|
+
match 'ls'
|
27
|
+
group 'Context'
|
28
|
+
description 'Show the list of vars and methods in the current scope.'
|
29
|
+
command_options :shellwords => false, :interpolate => false
|
30
|
+
|
31
|
+
banner <<-'BANNER'
|
32
|
+
Usage: ls [-m|-M|-p|-pM] [-q|-v] [-c|-i] [Object]
|
33
|
+
ls [-g] [-l]
|
34
|
+
|
35
|
+
ls shows you which methods, constants and variables are accessible to Pry. By
|
36
|
+
default it shows you the local variables defined in the current shell, and any
|
37
|
+
public methods or instance variables defined on the current object.
|
38
|
+
|
39
|
+
The colours used are configurable using Pry.config.ls.*_color, and the separator
|
40
|
+
is Pry.config.ls.separator.
|
41
|
+
|
42
|
+
Pry.config.ls.ceiling is used to hide methods defined higher up in the
|
43
|
+
inheritance chain, this is by default set to [Object, Module, Class] so that
|
44
|
+
methods defined on all Objects are omitted. The -v flag can be used to ignore
|
45
|
+
this setting and show all methods, while the -q can be used to set the ceiling
|
46
|
+
much lower and show only methods defined on the object or its direct class.
|
47
|
+
|
48
|
+
Also check out `find-method` command (run `help find-method`).
|
49
|
+
BANNER
|
50
|
+
|
51
|
+
|
52
|
+
def options(opt)
|
53
|
+
opt.on :m, :methods, "Show public methods defined on the Object"
|
54
|
+
opt.on :M, "instance-methods", "Show public methods defined in a Module or Class"
|
55
|
+
opt.on :p, :ppp, "Show public, protected (in yellow) and private (in green) methods"
|
56
|
+
opt.on :q, :quiet, "Show only methods defined on object.singleton_class and object.class"
|
57
|
+
opt.on :v, :verbose, "Show methods and constants on all super-classes (ignores Pry.config.ls.ceiling)"
|
58
|
+
opt.on :g, :globals, "Show global variables, including those builtin to Ruby (in cyan)"
|
59
|
+
opt.on :l, :locals, "Show hash of local vars, sorted by descending size"
|
60
|
+
opt.on :c, :constants, "Show constants, highlighting classes (in blue), and exceptions (in purple).\n" <<
|
61
|
+
" " * 32 << "Constants that are pending autoload? are also shown (in yellow)"
|
62
|
+
opt.on :i, :ivars, "Show instance variables (in blue) and class variables (in bright blue)"
|
63
|
+
opt.on :G, :grep, "Filter output by regular expression", :argument => true
|
64
|
+
|
65
|
+
if jruby?
|
66
|
+
opt.on :J, "all-java", "Show all the aliases for methods from java (default is to show only prettiest)"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# Exclude -q, -v and --grep because they,
|
71
|
+
# don't specify what the user wants to see.
|
72
|
+
def no_user_opts?
|
73
|
+
!(opts[:methods] || opts['instance-methods'] || opts[:ppp] ||
|
74
|
+
opts[:globals] || opts[:locals] || opts[:constants] || opts[:ivars])
|
75
|
+
end
|
76
|
+
|
77
|
+
def process
|
78
|
+
@interrogatee = args.empty? ? target_self : target.eval(args.join(' '))
|
79
|
+
raise_errors_if_arguments_are_weird
|
80
|
+
ls_entity = LsEntity.new({
|
81
|
+
:interrogatee => @interrogatee,
|
82
|
+
:no_user_opts => no_user_opts?,
|
83
|
+
:opts => opts,
|
84
|
+
:args => args,
|
85
|
+
:_pry_ => _pry_
|
86
|
+
})
|
87
|
+
|
88
|
+
_pry_.pager.page ls_entity.entities_table
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
def error_list
|
94
|
+
any_args = args.any?
|
95
|
+
non_mod_interrogatee = !(Module === @interrogatee)
|
96
|
+
[
|
97
|
+
['-l does not make sense with a specified Object', :locals, any_args],
|
98
|
+
['-g does not make sense with a specified Object', :globals, any_args],
|
99
|
+
['-q does not make sense with -v', :quiet, opts.present?(:verbose)],
|
100
|
+
['-M only makes sense with a Module or a Class', 'instance-methods', non_mod_interrogatee],
|
101
|
+
['-c only makes sense with a Module or a Class', :constants, any_args && non_mod_interrogatee]
|
102
|
+
]
|
103
|
+
end
|
104
|
+
|
105
|
+
def raise_errors_if_arguments_are_weird
|
106
|
+
error_list.each do |message, option, invalid_expr|
|
107
|
+
raise Pry::CommandError, message if opts.present?(option) && invalid_expr
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
Pry::Commands.add_command(Pry::Command::Ls)
|
114
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'pry/commands/ls/interrogatable'
|
2
|
+
|
3
|
+
class Pry
|
4
|
+
class Command::Ls < Pry::ClassCommand
|
5
|
+
class Constants < Pry::Command::Ls::Formatter
|
6
|
+
include Pry::Command::Ls::Interrogatable
|
7
|
+
|
8
|
+
|
9
|
+
def initialize(interrogatee, no_user_opts, opts, _pry_)
|
10
|
+
super(_pry_)
|
11
|
+
@interrogatee = interrogatee
|
12
|
+
@no_user_opts = no_user_opts
|
13
|
+
@default_switch = opts[:constants]
|
14
|
+
@verbose_switch = opts[:verbose]
|
15
|
+
end
|
16
|
+
|
17
|
+
def correct_opts?
|
18
|
+
super || (@no_user_opts && interrogating_a_module?)
|
19
|
+
end
|
20
|
+
|
21
|
+
def output_self
|
22
|
+
mod = interrogatee_mod
|
23
|
+
constants = WrappedModule.new(mod).constants(@verbose_switch)
|
24
|
+
output_section('constants', grep.regexp[format(mod, constants)])
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def format(mod, constants)
|
30
|
+
constants.sort_by(&:downcase).map do |name|
|
31
|
+
if const = (!mod.autoload?(name) && (mod.const_get(name) || true) rescue nil)
|
32
|
+
if (const < Exception rescue false)
|
33
|
+
color(:exception_constant, name)
|
34
|
+
elsif (Module === mod.const_get(name) rescue false)
|
35
|
+
color(:class_constant, name)
|
36
|
+
else
|
37
|
+
color(:constant, name)
|
38
|
+
end
|
39
|
+
else
|
40
|
+
color(:unloaded_constant, name)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::Ls < Pry::ClassCommand
|
3
|
+
class Formatter
|
4
|
+
attr_accessor :grep
|
5
|
+
attr_reader :_pry_
|
6
|
+
|
7
|
+
def initialize(_pry_)
|
8
|
+
@_pry_ = _pry_
|
9
|
+
@target = _pry_.current_context
|
10
|
+
end
|
11
|
+
|
12
|
+
def write_out
|
13
|
+
return false unless correct_opts?
|
14
|
+
output_self
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def color(type, str)
|
20
|
+
Pry::Helpers::Text.send _pry_.config.ls["#{type}_color"], str
|
21
|
+
end
|
22
|
+
|
23
|
+
# Add a new section to the output.
|
24
|
+
# Outputs nothing if the section would be empty.
|
25
|
+
def output_section(heading, body)
|
26
|
+
return '' if body.compact.empty?
|
27
|
+
fancy_heading = Pry::Helpers::Text.bold(color(:heading, heading))
|
28
|
+
Pry::Helpers.tablify_or_one_line(fancy_heading, body)
|
29
|
+
end
|
30
|
+
|
31
|
+
def format_value(value)
|
32
|
+
Pry::ColorPrinter.pp(value, '')
|
33
|
+
end
|
34
|
+
|
35
|
+
def correct_opts?
|
36
|
+
@default_switch
|
37
|
+
end
|
38
|
+
|
39
|
+
def output_self
|
40
|
+
raise NotImplementedError
|
41
|
+
end
|
42
|
+
|
43
|
+
def grep
|
44
|
+
@grep || proc { |x| x }
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::Ls < Pry::ClassCommand
|
3
|
+
class Globals < Pry::Command::Ls::Formatter
|
4
|
+
|
5
|
+
# Taken from "puts global_variables.inspect".
|
6
|
+
BUILTIN_GLOBALS =
|
7
|
+
%w($" $$ $* $, $-0 $-F $-I $-K $-W $-a $-d $-i $-l $-p $-v $-w $. $/ $\\
|
8
|
+
$: $; $< $= $> $0 $ARGV $CONSOLE $DEBUG $DEFAULT_INPUT $DEFAULT_OUTPUT
|
9
|
+
$FIELD_SEPARATOR $FILENAME $FS $IGNORECASE $INPUT_LINE_NUMBER
|
10
|
+
$INPUT_RECORD_SEPARATOR $KCODE $LOADED_FEATURES $LOAD_PATH $NR $OFS
|
11
|
+
$ORS $OUTPUT_FIELD_SEPARATOR $OUTPUT_RECORD_SEPARATOR $PID $PROCESS_ID
|
12
|
+
$PROGRAM_NAME $RS $VERBOSE $deferr $defout $stderr $stdin $stdout)
|
13
|
+
|
14
|
+
# `$SAFE` and `$?` are thread-local, the exception stuff only works in a
|
15
|
+
# rescue clause, everything else is basically a local variable with a `$`
|
16
|
+
# in its name.
|
17
|
+
PSEUDO_GLOBALS =
|
18
|
+
%w($! $' $& $` $@ $? $+ $_ $~ $1 $2 $3 $4 $5 $6 $7 $8 $9
|
19
|
+
$CHILD_STATUS $SAFE $ERROR_INFO $ERROR_POSITION $LAST_MATCH_INFO
|
20
|
+
$LAST_PAREN_MATCH $LAST_READ_LINE $MATCH $POSTMATCH $PREMATCH)
|
21
|
+
|
22
|
+
def initialize(opts, _pry_)
|
23
|
+
super(_pry_)
|
24
|
+
@default_switch = opts[:globals]
|
25
|
+
end
|
26
|
+
|
27
|
+
def output_self
|
28
|
+
variables = format(@target.eval('global_variables'))
|
29
|
+
output_section('global variables', grep.regexp[variables])
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def format(globals)
|
35
|
+
globals.map(&:to_s).sort_by(&:downcase).map do |name|
|
36
|
+
if PSEUDO_GLOBALS.include?(name)
|
37
|
+
color(:pseudo_global, name)
|
38
|
+
elsif BUILTIN_GLOBALS.include?(name)
|
39
|
+
color(:builtin_global, name)
|
40
|
+
else
|
41
|
+
color(:global_var, name)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::Ls < Pry::ClassCommand
|
3
|
+
class Grep
|
4
|
+
|
5
|
+
def initialize(grep_regexp)
|
6
|
+
@grep_regexp = grep_regexp
|
7
|
+
end
|
8
|
+
|
9
|
+
def regexp
|
10
|
+
proc { |x|
|
11
|
+
if x.instance_of?(Array)
|
12
|
+
x.grep(@grep_regexp)
|
13
|
+
else
|
14
|
+
x =~ @grep_regexp
|
15
|
+
end
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|