pry 0.10.0.pre2-universal-mswin32
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 +25 -0
- data/README.md +406 -0
- data/bin/pry +16 -0
- data/lib/pry.rb +161 -0
- data/lib/pry/cli.rb +220 -0
- data/lib/pry/code.rb +346 -0
- 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 +692 -0
- data/lib/pry/command_set.rb +443 -0
- data/lib/pry/commands.rb +6 -0
- 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 +24 -0
- 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 +131 -0
- data/lib/pry/editor.rb +133 -0
- data/lib/pry/exceptions.rb +77 -0
- data/lib/pry/helpers.rb +5 -0
- data/lib/pry/helpers/base_helpers.rb +113 -0
- data/lib/pry/helpers/command_helpers.rb +156 -0
- data/lib/pry/helpers/documentation_helpers.rb +75 -0
- data/lib/pry/helpers/options_helpers.rb +27 -0
- data/lib/pry/helpers/table.rb +109 -0
- data/lib/pry/helpers/text.rb +107 -0
- data/lib/pry/history.rb +125 -0
- data/lib/pry/history_array.rb +121 -0
- data/lib/pry/hooks.rb +230 -0
- data/lib/pry/indent.rb +406 -0
- 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 +546 -0
- 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 +136 -0
- 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 +103 -0
- data/lib/pry/prompt.rb +26 -0
- data/lib/pry/pry_class.rb +375 -0
- data/lib/pry/pry_instance.rb +654 -0
- data/lib/pry/rbx_path.rb +22 -0
- data/lib/pry/repl.rb +202 -0
- data/lib/pry/repl_file_loader.rb +74 -0
- 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 +3 -0
- data/lib/pry/wrapped_module.rb +373 -0
- metadata +248 -0
@@ -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
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'pry/commands/ls/interrogatable'
|
2
|
+
|
3
|
+
class Pry
|
4
|
+
class Command::Ls < Pry::ClassCommand
|
5
|
+
class InstanceVars < Pry::Command::Ls::Formatter
|
6
|
+
include Pry::Command::Ls::Interrogatable
|
7
|
+
|
8
|
+
def initialize(interrogatee, no_user_opts, opts, _pry_)
|
9
|
+
super(_pry_)
|
10
|
+
@interrogatee = interrogatee
|
11
|
+
@no_user_opts = no_user_opts
|
12
|
+
@default_switch = opts[:ivars]
|
13
|
+
end
|
14
|
+
|
15
|
+
def correct_opts?
|
16
|
+
super || @no_user_opts
|
17
|
+
end
|
18
|
+
|
19
|
+
def output_self
|
20
|
+
ivars = if Object === @interrogatee
|
21
|
+
Pry::Method.safe_send(@interrogatee, :instance_variables)
|
22
|
+
else
|
23
|
+
[] #TODO: BasicObject support
|
24
|
+
end
|
25
|
+
kvars = Pry::Method.safe_send(interrogatee_mod, :class_variables)
|
26
|
+
ivars_out = output_section('instance variables', format(:instance_var, ivars))
|
27
|
+
kvars_out = output_section('class variables', format(:class_var, kvars))
|
28
|
+
ivars_out + kvars_out
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def format(type, vars)
|
34
|
+
vars.sort_by { |var| var.to_s.downcase }.map { |var| color(type, var) }
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Pry::Command::Ls::Interrogatable
|
2
|
+
|
3
|
+
private
|
4
|
+
|
5
|
+
def interrogating_a_module?
|
6
|
+
Module === @interrogatee
|
7
|
+
end
|
8
|
+
|
9
|
+
def interrogatee_mod
|
10
|
+
if interrogating_a_module?
|
11
|
+
@interrogatee
|
12
|
+
else
|
13
|
+
singleton = Pry::Method.singleton_class_of(@interrogatee)
|
14
|
+
singleton.ancestors.grep(::Class).reject { |c| c == singleton }.first
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Pry::Command::Ls::JRubyHacks
|
2
|
+
|
3
|
+
private
|
4
|
+
|
5
|
+
# JRuby creates lots of aliases for methods imported from java in an attempt
|
6
|
+
# to make life easier for ruby programmers. (e.g. getFooBar becomes
|
7
|
+
# get_foo_bar and foo_bar, and maybe foo_bar? if it returns a Boolean). The
|
8
|
+
# full transformations are in the assignAliases method of:
|
9
|
+
# https://github.com/jruby/jruby/blob/master/src/org/jruby/javasupport/JavaClass.java
|
10
|
+
#
|
11
|
+
# This has the unfortunate side-effect of making the output of ls even more
|
12
|
+
# incredibly verbose than it normally would be for these objects; and so we
|
13
|
+
# filter out all but the nicest of these aliases here.
|
14
|
+
#
|
15
|
+
# TODO: This is a little bit vague, better heuristics could be used.
|
16
|
+
# JRuby also has a lot of scala-specific logic, which we don't copy.
|
17
|
+
def trim_jruby_aliases(methods)
|
18
|
+
grouped = methods.group_by do |m|
|
19
|
+
m.name.sub(/\A(is|get|set)(?=[A-Z_])/, '').gsub(/[_?=]/, '').downcase
|
20
|
+
end
|
21
|
+
|
22
|
+
grouped.map do |key, values|
|
23
|
+
values = values.sort_by do |m|
|
24
|
+
rubbishness(m.name)
|
25
|
+
end
|
26
|
+
|
27
|
+
found = []
|
28
|
+
values.select do |x|
|
29
|
+
(!found.any? { |y| x == y }) && found << x
|
30
|
+
end
|
31
|
+
end.flatten(1)
|
32
|
+
end
|
33
|
+
|
34
|
+
# When removing jruby aliases, we want to keep the alias that is
|
35
|
+
# "least rubbish" according to this metric.
|
36
|
+
def rubbishness(name)
|
37
|
+
name.each_char.map { |x|
|
38
|
+
case x
|
39
|
+
when /[A-Z]/
|
40
|
+
1
|
41
|
+
when '?', '=', '!'
|
42
|
+
-2
|
43
|
+
else
|
44
|
+
0
|
45
|
+
end
|
46
|
+
}.inject(&:+) + (name.size / 100.0)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|