pry 0.10.pre.1-i386-mswin32 → 0.10.0.pre3-i386-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +702 -0
  3. data/LICENSE +2 -2
  4. data/{README.markdown → README.md} +41 -35
  5. data/lib/pry.rb +82 -139
  6. data/lib/pry/cli.rb +77 -30
  7. data/lib/pry/code.rb +122 -183
  8. data/lib/pry/code/code_file.rb +103 -0
  9. data/lib/pry/code/code_range.rb +71 -0
  10. data/lib/pry/code/loc.rb +92 -0
  11. data/lib/pry/code_object.rb +172 -0
  12. data/lib/pry/color_printer.rb +55 -0
  13. data/lib/pry/command.rb +184 -28
  14. data/lib/pry/command_set.rb +113 -59
  15. data/lib/pry/commands.rb +4 -27
  16. data/lib/pry/commands/amend_line.rb +99 -0
  17. data/lib/pry/commands/bang.rb +20 -0
  18. data/lib/pry/commands/bang_pry.rb +17 -0
  19. data/lib/pry/commands/cat.rb +62 -0
  20. data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
  21. data/lib/pry/commands/cat/exception_formatter.rb +77 -0
  22. data/lib/pry/commands/cat/file_formatter.rb +67 -0
  23. data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
  24. data/lib/pry/commands/cd.rb +41 -0
  25. data/lib/pry/commands/change_inspector.rb +27 -0
  26. data/lib/pry/commands/change_prompt.rb +26 -0
  27. data/lib/pry/commands/code_collector.rb +165 -0
  28. data/lib/pry/commands/disable_pry.rb +27 -0
  29. data/lib/pry/commands/disabled_commands.rb +2 -0
  30. data/lib/pry/commands/easter_eggs.rb +112 -0
  31. data/lib/pry/commands/edit.rb +195 -0
  32. data/lib/pry/commands/edit/exception_patcher.rb +25 -0
  33. data/lib/pry/commands/edit/file_and_line_locator.rb +36 -0
  34. data/lib/pry/commands/exit.rb +42 -0
  35. data/lib/pry/commands/exit_all.rb +29 -0
  36. data/lib/pry/commands/exit_program.rb +23 -0
  37. data/lib/pry/commands/find_method.rb +193 -0
  38. data/lib/pry/commands/fix_indent.rb +19 -0
  39. data/lib/pry/commands/gem_cd.rb +26 -0
  40. data/lib/pry/commands/gem_install.rb +32 -0
  41. data/lib/pry/commands/gem_list.rb +33 -0
  42. data/lib/pry/commands/gem_open.rb +29 -0
  43. data/lib/pry/commands/gist.rb +101 -0
  44. data/lib/pry/commands/help.rb +164 -0
  45. data/lib/pry/commands/hist.rb +180 -0
  46. data/lib/pry/commands/import_set.rb +22 -0
  47. data/lib/pry/commands/install_command.rb +53 -0
  48. data/lib/pry/commands/jump_to.rb +29 -0
  49. data/lib/pry/commands/list_inspectors.rb +35 -0
  50. data/lib/pry/commands/list_prompts.rb +35 -0
  51. data/lib/pry/commands/ls.rb +114 -0
  52. data/lib/pry/commands/ls/constants.rb +47 -0
  53. data/lib/pry/commands/ls/formatter.rb +49 -0
  54. data/lib/pry/commands/ls/globals.rb +48 -0
  55. data/lib/pry/commands/ls/grep.rb +21 -0
  56. data/lib/pry/commands/ls/instance_vars.rb +39 -0
  57. data/lib/pry/commands/ls/interrogatable.rb +18 -0
  58. data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
  59. data/lib/pry/commands/ls/local_names.rb +35 -0
  60. data/lib/pry/commands/ls/local_vars.rb +39 -0
  61. data/lib/pry/commands/ls/ls_entity.rb +70 -0
  62. data/lib/pry/commands/ls/methods.rb +57 -0
  63. data/lib/pry/commands/ls/methods_helper.rb +46 -0
  64. data/lib/pry/commands/ls/self_methods.rb +32 -0
  65. data/lib/pry/commands/nesting.rb +25 -0
  66. data/lib/pry/commands/play.rb +103 -0
  67. data/lib/pry/commands/pry_backtrace.rb +25 -0
  68. data/lib/pry/commands/pry_version.rb +17 -0
  69. data/lib/pry/commands/raise_up.rb +32 -0
  70. data/lib/pry/commands/reload_code.rb +62 -0
  71. data/lib/pry/commands/reset.rb +18 -0
  72. data/lib/pry/commands/ri.rb +60 -0
  73. data/lib/pry/commands/save_file.rb +61 -0
  74. data/lib/pry/commands/shell_command.rb +48 -0
  75. data/lib/pry/commands/shell_mode.rb +25 -0
  76. data/lib/pry/commands/show_doc.rb +83 -0
  77. data/lib/pry/commands/show_info.rb +195 -0
  78. data/lib/pry/commands/show_input.rb +17 -0
  79. data/lib/pry/commands/show_source.rb +50 -0
  80. data/lib/pry/commands/simple_prompt.rb +22 -0
  81. data/lib/pry/commands/stat.rb +40 -0
  82. data/lib/pry/commands/switch_to.rb +23 -0
  83. data/lib/pry/commands/toggle_color.rb +24 -0
  84. data/lib/pry/commands/watch_expression.rb +105 -0
  85. data/lib/pry/commands/watch_expression/expression.rb +38 -0
  86. data/lib/pry/commands/whereami.rb +190 -0
  87. data/lib/pry/commands/wtf.rb +57 -0
  88. data/lib/pry/config.rb +20 -229
  89. data/lib/pry/config/behavior.rb +139 -0
  90. data/lib/pry/config/convenience.rb +26 -0
  91. data/lib/pry/config/default.rb +165 -0
  92. data/lib/pry/core_extensions.rb +59 -38
  93. data/lib/pry/editor.rb +133 -0
  94. data/lib/pry/exceptions.rb +77 -0
  95. data/lib/pry/helpers.rb +1 -0
  96. data/lib/pry/helpers/base_helpers.rb +40 -154
  97. data/lib/pry/helpers/command_helpers.rb +19 -130
  98. data/lib/pry/helpers/documentation_helpers.rb +21 -11
  99. data/lib/pry/helpers/table.rb +109 -0
  100. data/lib/pry/helpers/text.rb +8 -9
  101. data/lib/pry/history.rb +61 -45
  102. data/lib/pry/history_array.rb +11 -1
  103. data/lib/pry/hooks.rb +10 -32
  104. data/lib/pry/indent.rb +110 -38
  105. data/lib/pry/input_completer.rb +242 -0
  106. data/lib/pry/input_lock.rb +132 -0
  107. data/lib/pry/inspector.rb +27 -0
  108. data/lib/pry/last_exception.rb +61 -0
  109. data/lib/pry/method.rb +199 -200
  110. data/lib/pry/method/disowned.rb +53 -0
  111. data/lib/pry/method/patcher.rb +125 -0
  112. data/lib/pry/method/weird_method_locator.rb +186 -0
  113. data/lib/pry/module_candidate.rb +39 -33
  114. data/lib/pry/object_path.rb +82 -0
  115. data/lib/pry/output.rb +50 -0
  116. data/lib/pry/pager.rb +234 -0
  117. data/lib/pry/plugins.rb +4 -3
  118. data/lib/pry/prompt.rb +26 -0
  119. data/lib/pry/pry_class.rb +199 -227
  120. data/lib/pry/pry_instance.rb +344 -403
  121. data/lib/pry/rbx_path.rb +1 -1
  122. data/lib/pry/repl.rb +202 -0
  123. data/lib/pry/repl_file_loader.rb +20 -26
  124. data/lib/pry/rubygem.rb +82 -0
  125. data/lib/pry/terminal.rb +79 -0
  126. data/lib/pry/test/helper.rb +170 -0
  127. data/lib/pry/version.rb +1 -1
  128. data/lib/pry/wrapped_module.rb +133 -48
  129. metadata +132 -197
  130. data/.document +0 -2
  131. data/.gemtest +0 -0
  132. data/.gitignore +0 -16
  133. data/.travis.yml +0 -17
  134. data/.yardopts +0 -1
  135. data/CHANGELOG +0 -387
  136. data/CONTRIBUTORS +0 -36
  137. data/Gemfile +0 -2
  138. data/Rakefile +0 -137
  139. data/TODO +0 -117
  140. data/examples/example_basic.rb +0 -15
  141. data/examples/example_command_override.rb +0 -32
  142. data/examples/example_commands.rb +0 -36
  143. data/examples/example_hooks.rb +0 -9
  144. data/examples/example_image_edit.rb +0 -67
  145. data/examples/example_input.rb +0 -7
  146. data/examples/example_input2.rb +0 -29
  147. data/examples/example_output.rb +0 -11
  148. data/examples/example_print.rb +0 -6
  149. data/examples/example_prompt.rb +0 -9
  150. data/examples/helper.rb +0 -6
  151. data/lib/pry/completion.rb +0 -221
  152. data/lib/pry/custom_completions.rb +0 -6
  153. data/lib/pry/default_commands/cd.rb +0 -81
  154. data/lib/pry/default_commands/commands.rb +0 -62
  155. data/lib/pry/default_commands/context.rb +0 -98
  156. data/lib/pry/default_commands/easter_eggs.rb +0 -95
  157. data/lib/pry/default_commands/editing.rb +0 -420
  158. data/lib/pry/default_commands/find_method.rb +0 -169
  159. data/lib/pry/default_commands/gems.rb +0 -84
  160. data/lib/pry/default_commands/gist.rb +0 -187
  161. data/lib/pry/default_commands/help.rb +0 -127
  162. data/lib/pry/default_commands/hist.rb +0 -120
  163. data/lib/pry/default_commands/input_and_output.rb +0 -306
  164. data/lib/pry/default_commands/introspection.rb +0 -410
  165. data/lib/pry/default_commands/ls.rb +0 -272
  166. data/lib/pry/default_commands/misc.rb +0 -38
  167. data/lib/pry/default_commands/navigating_pry.rb +0 -110
  168. data/lib/pry/default_commands/whereami.rb +0 -92
  169. data/lib/pry/extended_commands/experimental.rb +0 -7
  170. data/lib/pry/rbx_method.rb +0 -13
  171. data/man/pry.1 +0 -195
  172. data/man/pry.1.html +0 -204
  173. data/man/pry.1.ronn +0 -141
  174. data/pry.gemspec +0 -46
  175. data/test/candidate_helper1.rb +0 -11
  176. data/test/candidate_helper2.rb +0 -8
  177. data/test/helper.rb +0 -223
  178. data/test/test_cli.rb +0 -78
  179. data/test/test_code.rb +0 -201
  180. data/test/test_command.rb +0 -712
  181. data/test/test_command_helpers.rb +0 -9
  182. data/test/test_command_integration.rb +0 -668
  183. data/test/test_command_set.rb +0 -610
  184. data/test/test_completion.rb +0 -62
  185. data/test/test_control_d_handler.rb +0 -45
  186. data/test/test_default_commands/example.erb +0 -5
  187. data/test/test_default_commands/test_cd.rb +0 -318
  188. data/test/test_default_commands/test_context.rb +0 -280
  189. data/test/test_default_commands/test_documentation.rb +0 -314
  190. data/test/test_default_commands/test_find_method.rb +0 -50
  191. data/test/test_default_commands/test_gems.rb +0 -18
  192. data/test/test_default_commands/test_help.rb +0 -57
  193. data/test/test_default_commands/test_input.rb +0 -428
  194. data/test/test_default_commands/test_introspection.rb +0 -511
  195. data/test/test_default_commands/test_ls.rb +0 -151
  196. data/test/test_default_commands/test_shell.rb +0 -343
  197. data/test/test_default_commands/test_show_source.rb +0 -432
  198. data/test/test_exception_whitelist.rb +0 -21
  199. data/test/test_history_array.rb +0 -65
  200. data/test/test_hooks.rb +0 -521
  201. data/test/test_indent.rb +0 -277
  202. data/test/test_input_stack.rb +0 -86
  203. data/test/test_method.rb +0 -401
  204. data/test/test_pry.rb +0 -463
  205. data/test/test_pry_defaults.rb +0 -419
  206. data/test/test_pry_history.rb +0 -84
  207. data/test/test_pry_output.rb +0 -41
  208. data/test/test_sticky_locals.rb +0 -155
  209. data/test/test_syntax_checking.rb +0 -65
  210. data/test/test_wrapped_module.rb +0 -174
  211. data/test/testrc +0 -2
  212. data/test/testrcbad +0 -2
  213. data/wiki/Customizing-pry.md +0 -397
  214. 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