pry 0.9.12.6-java → 0.10.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +702 -0
  3. data/LICENSE +2 -2
  4. data/{README.markdown → README.md} +37 -31
  5. data/lib/pry.rb +38 -151
  6. data/lib/pry/cli.rb +35 -17
  7. data/lib/pry/code.rb +19 -63
  8. data/lib/pry/code/code_file.rb +103 -0
  9. data/lib/pry/code/code_range.rb +2 -1
  10. data/lib/pry/code/loc.rb +2 -2
  11. data/lib/pry/code_object.rb +40 -21
  12. data/lib/pry/color_printer.rb +55 -0
  13. data/lib/pry/command.rb +12 -9
  14. data/lib/pry/command_set.rb +81 -38
  15. data/lib/pry/commands.rb +1 -1
  16. data/lib/pry/commands/amend_line.rb +2 -2
  17. data/lib/pry/commands/bang.rb +1 -1
  18. data/lib/pry/commands/cat.rb +11 -2
  19. data/lib/pry/commands/cat/exception_formatter.rb +6 -7
  20. data/lib/pry/commands/cat/file_formatter.rb +15 -32
  21. data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
  22. data/lib/pry/commands/cd.rb +14 -3
  23. data/lib/pry/commands/change_inspector.rb +27 -0
  24. data/lib/pry/commands/change_prompt.rb +26 -0
  25. data/lib/pry/commands/code_collector.rb +4 -4
  26. data/lib/pry/commands/easter_eggs.rb +3 -3
  27. data/lib/pry/commands/edit.rb +10 -22
  28. data/lib/pry/commands/edit/exception_patcher.rb +2 -2
  29. data/lib/pry/commands/edit/file_and_line_locator.rb +0 -2
  30. data/lib/pry/commands/exit_program.rb +0 -1
  31. data/lib/pry/commands/find_method.rb +16 -22
  32. data/lib/pry/commands/gem_install.rb +5 -2
  33. data/lib/pry/commands/gem_open.rb +1 -1
  34. data/lib/pry/commands/gist.rb +10 -11
  35. data/lib/pry/commands/help.rb +14 -14
  36. data/lib/pry/commands/hist.rb +27 -8
  37. data/lib/pry/commands/install_command.rb +14 -12
  38. data/lib/pry/commands/list_inspectors.rb +35 -0
  39. data/lib/pry/commands/list_prompts.rb +35 -0
  40. data/lib/pry/commands/ls.rb +72 -296
  41. data/lib/pry/commands/ls/constants.rb +47 -0
  42. data/lib/pry/commands/ls/formatter.rb +49 -0
  43. data/lib/pry/commands/ls/globals.rb +48 -0
  44. data/lib/pry/commands/ls/grep.rb +21 -0
  45. data/lib/pry/commands/ls/instance_vars.rb +39 -0
  46. data/lib/pry/commands/ls/interrogatable.rb +18 -0
  47. data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
  48. data/lib/pry/commands/ls/local_names.rb +35 -0
  49. data/lib/pry/commands/ls/local_vars.rb +39 -0
  50. data/lib/pry/commands/ls/ls_entity.rb +70 -0
  51. data/lib/pry/commands/ls/methods.rb +57 -0
  52. data/lib/pry/commands/ls/methods_helper.rb +46 -0
  53. data/lib/pry/commands/ls/self_methods.rb +32 -0
  54. data/lib/pry/commands/play.rb +44 -10
  55. data/lib/pry/commands/pry_backtrace.rb +1 -2
  56. data/lib/pry/commands/raise_up.rb +2 -2
  57. data/lib/pry/commands/reload_code.rb +16 -19
  58. data/lib/pry/commands/ri.rb +7 -3
  59. data/lib/pry/commands/shell_command.rb +18 -13
  60. data/lib/pry/commands/shell_mode.rb +2 -4
  61. data/lib/pry/commands/show_doc.rb +5 -0
  62. data/lib/pry/commands/show_info.rb +8 -13
  63. data/lib/pry/commands/show_source.rb +15 -3
  64. data/lib/pry/commands/simple_prompt.rb +1 -1
  65. data/lib/pry/commands/toggle_color.rb +8 -4
  66. data/lib/pry/commands/watch_expression.rb +105 -0
  67. data/lib/pry/commands/watch_expression/expression.rb +38 -0
  68. data/lib/pry/commands/whereami.rb +18 -10
  69. data/lib/pry/commands/wtf.rb +3 -3
  70. data/lib/pry/config.rb +20 -254
  71. data/lib/pry/config/behavior.rb +139 -0
  72. data/lib/pry/config/convenience.rb +26 -0
  73. data/lib/pry/config/default.rb +165 -0
  74. data/lib/pry/core_extensions.rb +31 -21
  75. data/lib/pry/editor.rb +107 -103
  76. data/lib/pry/exceptions.rb +77 -0
  77. data/lib/pry/helpers/base_helpers.rb +22 -109
  78. data/lib/pry/helpers/command_helpers.rb +10 -8
  79. data/lib/pry/helpers/documentation_helpers.rb +1 -2
  80. data/lib/pry/helpers/text.rb +4 -5
  81. data/lib/pry/history.rb +46 -45
  82. data/lib/pry/history_array.rb +6 -1
  83. data/lib/pry/hooks.rb +9 -29
  84. data/lib/pry/indent.rb +6 -6
  85. data/lib/pry/input_completer.rb +242 -0
  86. data/lib/pry/input_lock.rb +132 -0
  87. data/lib/pry/inspector.rb +27 -0
  88. data/lib/pry/last_exception.rb +61 -0
  89. data/lib/pry/method.rb +82 -87
  90. data/lib/pry/{commands/edit/method_patcher.rb → method/patcher.rb} +41 -38
  91. data/lib/pry/module_candidate.rb +4 -14
  92. data/lib/pry/object_path.rb +82 -0
  93. data/lib/pry/output.rb +50 -0
  94. data/lib/pry/pager.rb +193 -48
  95. data/lib/pry/plugins.rb +1 -1
  96. data/lib/pry/prompt.rb +26 -0
  97. data/lib/pry/pry_class.rb +149 -230
  98. data/lib/pry/pry_instance.rb +302 -413
  99. data/lib/pry/rbx_path.rb +1 -1
  100. data/lib/pry/repl.rb +202 -0
  101. data/lib/pry/repl_file_loader.rb +20 -26
  102. data/lib/pry/rubygem.rb +13 -5
  103. data/lib/pry/terminal.rb +2 -1
  104. data/lib/pry/test/helper.rb +26 -41
  105. data/lib/pry/version.rb +1 -1
  106. data/lib/pry/wrapped_module.rb +45 -59
  107. metadata +62 -225
  108. data/.document +0 -2
  109. data/.gitignore +0 -16
  110. data/.travis.yml +0 -25
  111. data/.yardopts +0 -1
  112. data/CHANGELOG +0 -534
  113. data/CONTRIBUTORS +0 -55
  114. data/Gemfile +0 -12
  115. data/Rakefile +0 -140
  116. data/TODO +0 -117
  117. data/lib/pry/completion.rb +0 -321
  118. data/lib/pry/custom_completions.rb +0 -6
  119. data/lib/pry/rbx_method.rb +0 -13
  120. data/man/pry.1 +0 -195
  121. data/man/pry.1.html +0 -204
  122. data/man/pry.1.ronn +0 -141
  123. data/pry.gemspec +0 -29
  124. data/spec/Procfile +0 -3
  125. data/spec/cli_spec.rb +0 -78
  126. data/spec/code_object_spec.rb +0 -277
  127. data/spec/code_spec.rb +0 -219
  128. data/spec/command_helpers_spec.rb +0 -29
  129. data/spec/command_integration_spec.rb +0 -644
  130. data/spec/command_set_spec.rb +0 -627
  131. data/spec/command_spec.rb +0 -821
  132. data/spec/commands/amend_line_spec.rb +0 -247
  133. data/spec/commands/bang_spec.rb +0 -19
  134. data/spec/commands/cat_spec.rb +0 -164
  135. data/spec/commands/cd_spec.rb +0 -250
  136. data/spec/commands/disable_pry_spec.rb +0 -25
  137. data/spec/commands/edit_spec.rb +0 -727
  138. data/spec/commands/exit_all_spec.rb +0 -34
  139. data/spec/commands/exit_program_spec.rb +0 -19
  140. data/spec/commands/exit_spec.rb +0 -34
  141. data/spec/commands/find_method_spec.rb +0 -70
  142. data/spec/commands/gem_list_spec.rb +0 -26
  143. data/spec/commands/gist_spec.rb +0 -79
  144. data/spec/commands/help_spec.rb +0 -56
  145. data/spec/commands/hist_spec.rb +0 -181
  146. data/spec/commands/jump_to_spec.rb +0 -15
  147. data/spec/commands/ls_spec.rb +0 -181
  148. data/spec/commands/play_spec.rb +0 -140
  149. data/spec/commands/raise_up_spec.rb +0 -56
  150. data/spec/commands/save_file_spec.rb +0 -177
  151. data/spec/commands/show_doc_spec.rb +0 -510
  152. data/spec/commands/show_input_spec.rb +0 -17
  153. data/spec/commands/show_source_spec.rb +0 -782
  154. data/spec/commands/whereami_spec.rb +0 -203
  155. data/spec/completion_spec.rb +0 -241
  156. data/spec/control_d_handler_spec.rb +0 -58
  157. data/spec/documentation_helper_spec.rb +0 -73
  158. data/spec/editor_spec.rb +0 -79
  159. data/spec/exception_whitelist_spec.rb +0 -21
  160. data/spec/fixtures/candidate_helper1.rb +0 -11
  161. data/spec/fixtures/candidate_helper2.rb +0 -8
  162. data/spec/fixtures/example.erb +0 -5
  163. data/spec/fixtures/example_nesting.rb +0 -33
  164. data/spec/fixtures/show_source_doc_examples.rb +0 -15
  165. data/spec/fixtures/testrc +0 -2
  166. data/spec/fixtures/testrcbad +0 -2
  167. data/spec/fixtures/whereami_helper.rb +0 -6
  168. data/spec/helper.rb +0 -34
  169. data/spec/helpers/bacon.rb +0 -86
  170. data/spec/helpers/mock_pry.rb +0 -43
  171. data/spec/helpers/table_spec.rb +0 -105
  172. data/spec/history_array_spec.rb +0 -67
  173. data/spec/hooks_spec.rb +0 -522
  174. data/spec/indent_spec.rb +0 -301
  175. data/spec/input_stack_spec.rb +0 -90
  176. data/spec/method_spec.rb +0 -482
  177. data/spec/prompt_spec.rb +0 -60
  178. data/spec/pry_defaults_spec.rb +0 -419
  179. data/spec/pry_history_spec.rb +0 -99
  180. data/spec/pry_output_spec.rb +0 -95
  181. data/spec/pry_spec.rb +0 -515
  182. data/spec/run_command_spec.rb +0 -25
  183. data/spec/sticky_locals_spec.rb +0 -157
  184. data/spec/syntax_checking_spec.rb +0 -81
  185. data/spec/wrapped_module_spec.rb +0 -261
  186. data/wiki/Customizing-pry.md +0 -397
  187. data/wiki/Home.md +0 -4
@@ -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
@@ -0,0 +1,35 @@
1
+ class Pry
2
+ class Command::Ls < Pry::ClassCommand
3
+ class LocalNames < Pry::Command::Ls::Formatter
4
+
5
+ def initialize(no_user_opts, args, _pry_)
6
+ super(_pry_)
7
+ @no_user_opts = no_user_opts
8
+ @args = args
9
+ @sticky_locals = _pry_.sticky_locals
10
+ end
11
+
12
+ def correct_opts?
13
+ super || (@no_user_opts && @args.empty?)
14
+ end
15
+
16
+ def output_self
17
+ local_vars = grep.regexp[@target.eval('local_variables')]
18
+ output_section('locals', format(local_vars))
19
+ end
20
+
21
+ private
22
+
23
+ def format(locals)
24
+ locals.sort_by(&:downcase).map do |name|
25
+ if @sticky_locals.include?(name.to_sym)
26
+ color(:pry_var, name)
27
+ else
28
+ color(:local_var, name)
29
+ end
30
+ end
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,39 @@
1
+ class Pry
2
+ class Command::Ls < Pry::ClassCommand
3
+ class LocalVars < Pry::Command::Ls::Formatter
4
+
5
+ def initialize(opts, _pry_)
6
+ super(_pry_)
7
+ @default_switch = opts[:locals]
8
+ @sticky_locals = _pry_.sticky_locals
9
+ end
10
+
11
+ def output_self
12
+ name_value_pairs = @target.eval('local_variables').reject { |e|
13
+ @sticky_locals.keys.include?(e.to_sym)
14
+ }.map { |name|
15
+ [name, (@target.eval(name.to_s))]
16
+ }
17
+ format(name_value_pairs).join('')
18
+ end
19
+
20
+ private
21
+
22
+ def format(name_value_pairs)
23
+ name_value_pairs.sort_by { |name, value|
24
+ value.to_s.size
25
+ }.reverse.map { |name, value|
26
+ colorized_assignment_style(name, format_value(value))
27
+ }
28
+ end
29
+
30
+ def colorized_assignment_style(lhs, rhs, desired_width = 7)
31
+ colorized_lhs = color(:local_var, lhs)
32
+ color_escape_padding = colorized_lhs.size - lhs.size
33
+ pad = desired_width + color_escape_padding
34
+ "%-#{pad}s = %s" % [color(:local_var, colorized_lhs), rhs]
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,70 @@
1
+ require 'pry/commands/ls/grep'
2
+ require 'pry/commands/ls/formatter'
3
+ require 'pry/commands/ls/globals'
4
+ require 'pry/commands/ls/constants'
5
+ require 'pry/commands/ls/methods'
6
+ require 'pry/commands/ls/self_methods'
7
+ require 'pry/commands/ls/instance_vars'
8
+ require 'pry/commands/ls/local_names'
9
+ require 'pry/commands/ls/local_vars'
10
+
11
+ class Pry
12
+ class Command::Ls < Pry::ClassCommand
13
+
14
+ class LsEntity
15
+ attr_reader :_pry_
16
+
17
+ def initialize(opts)
18
+ @interrogatee = opts[:interrogatee]
19
+ @no_user_opts = opts[:no_user_opts]
20
+ @opts = opts[:opts]
21
+ @args = opts[:args]
22
+ @grep = Grep.new(Regexp.new(opts[:opts][:G] || '.'))
23
+ @_pry_ = opts.delete(:_pry_)
24
+ end
25
+
26
+ def entities_table
27
+ entities.map(&:write_out).reject { |o| !o }.join('')
28
+ end
29
+
30
+ private
31
+
32
+ def grep(entity)
33
+ entity.tap { |o| o.grep = @grep }
34
+ end
35
+
36
+ def globals
37
+ grep Globals.new(@opts, _pry_)
38
+ end
39
+
40
+ def constants
41
+ grep Constants.new(@interrogatee, @no_user_opts, @opts, _pry_)
42
+ end
43
+
44
+ def methods
45
+ grep(Methods.new(@interrogatee, @no_user_opts, @opts, _pry_))
46
+ end
47
+
48
+ def self_methods
49
+ grep SelfMethods.new(@interrogatee, @no_user_opts, @opts, _pry_)
50
+ end
51
+
52
+ def instance_vars
53
+ grep InstanceVars.new(@interrogatee, @no_user_opts, @opts, _pry_)
54
+ end
55
+
56
+ def local_names
57
+ grep LocalNames.new(@no_user_opts, @args, _pry_)
58
+ end
59
+
60
+ def local_vars
61
+ LocalVars.new(@opts, _pry_)
62
+ end
63
+
64
+ def entities
65
+ [globals, constants, methods, self_methods, instance_vars, local_names,
66
+ local_vars]
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,57 @@
1
+ require 'pry/commands/ls/methods_helper'
2
+ require 'pry/commands/ls/interrogatable'
3
+
4
+ class Pry
5
+ class Command::Ls < Pry::ClassCommand
6
+ class Methods < Pry::Command::Ls::Formatter
7
+
8
+ include Pry::Command::Ls::Interrogatable
9
+ include Pry::Command::Ls::MethodsHelper
10
+
11
+ def initialize(interrogatee, no_user_opts, opts, _pry_)
12
+ super(_pry_)
13
+ @interrogatee = interrogatee
14
+ @no_user_opts = no_user_opts
15
+ @default_switch = opts[:methods]
16
+ @instance_methods_switch = opts['instance-methods']
17
+ @ppp_switch = opts[:ppp]
18
+ @jruby_switch = opts['all-java']
19
+ @quiet_switch = opts[:quiet]
20
+ @verbose_switch = opts[:verbose]
21
+ end
22
+
23
+ def output_self
24
+ methods = all_methods.group_by(&:owner)
25
+ # Reverse the resolution order so that the most useful information
26
+ # appears right by the prompt.
27
+ resolution_order.take_while(&below_ceiling).reverse.map do |klass|
28
+ methods_here = (methods[klass] || []).select { |m| grep.regexp[m.name] }
29
+ heading = "#{ Pry::WrappedModule.new(klass).method_prefix }methods"
30
+ output_section(heading, format(methods_here))
31
+ end.join('')
32
+ end
33
+
34
+ private
35
+
36
+ def correct_opts?
37
+ super || @instance_methods_switch || @ppp_switch || @no_user_opts
38
+ end
39
+
40
+
41
+ # Get a lambda that can be used with `take_while` to prevent over-eager
42
+ # traversal of the Object's ancestry graph.
43
+ def below_ceiling
44
+ ceiling = if @quiet_switch
45
+ [Pry::Method.safe_send(interrogatee_mod, :ancestors)[1]] +
46
+ _pry_.config.ls.ceiling
47
+ elsif @verbose_switch
48
+ []
49
+ else
50
+ _pry_.config.ls.ceiling.dup
51
+ end
52
+ lambda { |klass| !ceiling.include?(klass) }
53
+ end
54
+
55
+ end
56
+ end
57
+ end