pry 0.10.3 → 0.14.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +439 -16
  3. data/LICENSE +1 -1
  4. data/README.md +362 -302
  5. data/bin/pry +4 -7
  6. data/lib/pry/basic_object.rb +10 -0
  7. data/lib/pry/block_command.rb +22 -0
  8. data/lib/pry/class_command.rb +194 -0
  9. data/lib/pry/cli.rb +84 -97
  10. data/lib/pry/code/code_file.rb +37 -26
  11. data/lib/pry/code/code_range.rb +7 -5
  12. data/lib/pry/code/loc.rb +26 -13
  13. data/lib/pry/code.rb +42 -31
  14. data/lib/pry/code_object.rb +53 -28
  15. data/lib/pry/color_printer.rb +46 -35
  16. data/lib/pry/command.rb +197 -369
  17. data/lib/pry/command_set.rb +89 -114
  18. data/lib/pry/command_state.rb +31 -0
  19. data/lib/pry/commands/amend_line.rb +86 -82
  20. data/lib/pry/commands/bang.rb +18 -14
  21. data/lib/pry/commands/bang_pry.rb +15 -11
  22. data/lib/pry/commands/cat/abstract_formatter.rb +23 -18
  23. data/lib/pry/commands/cat/exception_formatter.rb +85 -72
  24. data/lib/pry/commands/cat/file_formatter.rb +56 -46
  25. data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
  26. data/lib/pry/commands/cat.rb +62 -54
  27. data/lib/pry/commands/cd.rb +40 -35
  28. data/lib/pry/commands/change_inspector.rb +29 -22
  29. data/lib/pry/commands/change_prompt.rb +48 -23
  30. data/lib/pry/commands/clear_screen.rb +20 -0
  31. data/lib/pry/commands/code_collector.rb +148 -131
  32. data/lib/pry/commands/disable_pry.rb +23 -19
  33. data/lib/pry/commands/easter_eggs.rb +23 -34
  34. data/lib/pry/commands/edit/exception_patcher.rb +21 -17
  35. data/lib/pry/commands/edit/file_and_line_locator.rb +34 -23
  36. data/lib/pry/commands/edit.rb +185 -157
  37. data/lib/pry/commands/exit.rb +40 -35
  38. data/lib/pry/commands/exit_all.rb +24 -20
  39. data/lib/pry/commands/exit_program.rb +20 -16
  40. data/lib/pry/commands/find_method.rb +168 -162
  41. data/lib/pry/commands/fix_indent.rb +16 -12
  42. data/lib/pry/commands/help.rb +140 -133
  43. data/lib/pry/commands/hist.rb +151 -149
  44. data/lib/pry/commands/import_set.rb +20 -15
  45. data/lib/pry/commands/jump_to.rb +25 -21
  46. data/lib/pry/commands/list_inspectors.rb +35 -28
  47. data/lib/pry/commands/ls/constants.rb +59 -31
  48. data/lib/pry/commands/ls/formatter.rb +42 -36
  49. data/lib/pry/commands/ls/globals.rb +38 -36
  50. data/lib/pry/commands/ls/grep.rb +17 -15
  51. data/lib/pry/commands/ls/instance_vars.rb +29 -28
  52. data/lib/pry/commands/ls/interrogatable.rb +18 -12
  53. data/lib/pry/commands/ls/jruby_hacks.rb +47 -41
  54. data/lib/pry/commands/ls/local_names.rb +26 -24
  55. data/lib/pry/commands/ls/local_vars.rb +38 -30
  56. data/lib/pry/commands/ls/ls_entity.rb +47 -52
  57. data/lib/pry/commands/ls/methods.rb +49 -51
  58. data/lib/pry/commands/ls/methods_helper.rb +46 -42
  59. data/lib/pry/commands/ls/self_methods.rb +23 -21
  60. data/lib/pry/commands/ls.rb +124 -103
  61. data/lib/pry/commands/nesting.rb +21 -17
  62. data/lib/pry/commands/play.rb +92 -82
  63. data/lib/pry/commands/pry_backtrace.rb +22 -17
  64. data/lib/pry/commands/pry_version.rb +15 -11
  65. data/lib/pry/commands/raise_up.rb +33 -27
  66. data/lib/pry/commands/reload_code.rb +60 -48
  67. data/lib/pry/commands/reset.rb +16 -12
  68. data/lib/pry/commands/ri.rb +57 -42
  69. data/lib/pry/commands/save_file.rb +45 -43
  70. data/lib/pry/commands/shell_command.rb +56 -29
  71. data/lib/pry/commands/shell_mode.rb +22 -18
  72. data/lib/pry/commands/show_doc.rb +80 -70
  73. data/lib/pry/commands/show_info.rb +194 -155
  74. data/lib/pry/commands/show_input.rb +16 -11
  75. data/lib/pry/commands/show_source.rb +110 -42
  76. data/lib/pry/commands/stat.rb +35 -31
  77. data/lib/pry/commands/switch_to.rb +21 -15
  78. data/lib/pry/commands/toggle_color.rb +20 -16
  79. data/lib/pry/commands/watch_expression/expression.rb +32 -27
  80. data/lib/pry/commands/watch_expression.rb +89 -84
  81. data/lib/pry/commands/whereami.rb +156 -141
  82. data/lib/pry/commands/wtf.rb +78 -40
  83. data/lib/pry/config/attributable.rb +22 -0
  84. data/lib/pry/config/lazy_value.rb +29 -0
  85. data/lib/pry/config/memoized_value.rb +34 -0
  86. data/lib/pry/config/value.rb +24 -0
  87. data/lib/pry/config.rb +310 -20
  88. data/lib/pry/control_d_handler.rb +28 -0
  89. data/lib/pry/core_extensions.rb +22 -9
  90. data/lib/pry/editor.rb +56 -34
  91. data/lib/pry/env.rb +18 -0
  92. data/lib/pry/exception_handler.rb +43 -0
  93. data/lib/pry/exceptions.rb +13 -18
  94. data/lib/pry/forwardable.rb +27 -0
  95. data/lib/pry/helpers/base_helpers.rb +20 -62
  96. data/lib/pry/helpers/command_helpers.rb +52 -62
  97. data/lib/pry/helpers/documentation_helpers.rb +21 -12
  98. data/lib/pry/helpers/options_helpers.rb +15 -8
  99. data/lib/pry/helpers/platform.rb +55 -0
  100. data/lib/pry/helpers/table.rb +44 -32
  101. data/lib/pry/helpers/text.rb +96 -85
  102. data/lib/pry/helpers.rb +3 -0
  103. data/lib/pry/history.rb +81 -55
  104. data/lib/pry/hooks.rb +60 -110
  105. data/lib/pry/indent.rb +74 -68
  106. data/lib/pry/input_completer.rb +199 -158
  107. data/lib/pry/input_lock.rb +7 -10
  108. data/lib/pry/inspector.rb +36 -24
  109. data/lib/pry/last_exception.rb +45 -45
  110. data/lib/pry/method/disowned.rb +19 -5
  111. data/lib/pry/method/patcher.rb +14 -8
  112. data/lib/pry/method/weird_method_locator.rb +79 -45
  113. data/lib/pry/method.rb +178 -124
  114. data/lib/pry/object_path.rb +37 -28
  115. data/lib/pry/output.rb +102 -16
  116. data/lib/pry/pager.rb +187 -174
  117. data/lib/pry/prompt.rb +213 -25
  118. data/lib/pry/pry_class.rb +119 -98
  119. data/lib/pry/pry_instance.rb +261 -224
  120. data/lib/pry/repl.rb +83 -29
  121. data/lib/pry/repl_file_loader.rb +27 -22
  122. data/lib/pry/ring.rb +89 -0
  123. data/lib/pry/slop/LICENSE +20 -0
  124. data/lib/pry/slop/commands.rb +190 -0
  125. data/lib/pry/slop/option.rb +210 -0
  126. data/lib/pry/slop.rb +672 -0
  127. data/lib/pry/syntax_highlighter.rb +26 -0
  128. data/lib/pry/system_command_handler.rb +17 -0
  129. data/lib/pry/testable/evalable.rb +24 -0
  130. data/lib/pry/testable/mockable.rb +22 -0
  131. data/lib/pry/testable/pry_tester.rb +88 -0
  132. data/lib/pry/testable/utility.rb +34 -0
  133. data/lib/pry/testable/variables.rb +52 -0
  134. data/lib/pry/testable.rb +68 -0
  135. data/lib/pry/version.rb +3 -1
  136. data/lib/pry/warning.rb +20 -0
  137. data/lib/pry/{module_candidate.rb → wrapped_module/candidate.rb} +35 -32
  138. data/lib/pry/wrapped_module.rb +68 -63
  139. data/lib/pry.rb +133 -149
  140. metadata +58 -69
  141. data/lib/pry/commands/disabled_commands.rb +0 -2
  142. data/lib/pry/commands/gem_cd.rb +0 -26
  143. data/lib/pry/commands/gem_install.rb +0 -32
  144. data/lib/pry/commands/gem_list.rb +0 -33
  145. data/lib/pry/commands/gem_open.rb +0 -29
  146. data/lib/pry/commands/gist.rb +0 -101
  147. data/lib/pry/commands/install_command.rb +0 -53
  148. data/lib/pry/commands/list_prompts.rb +0 -35
  149. data/lib/pry/commands/simple_prompt.rb +0 -22
  150. data/lib/pry/commands.rb +0 -6
  151. data/lib/pry/config/behavior.rb +0 -139
  152. data/lib/pry/config/convenience.rb +0 -25
  153. data/lib/pry/config/default.rb +0 -161
  154. data/lib/pry/history_array.rb +0 -121
  155. data/lib/pry/plugins.rb +0 -103
  156. data/lib/pry/rbx_path.rb +0 -22
  157. data/lib/pry/rubygem.rb +0 -82
  158. data/lib/pry/terminal.rb +0 -79
  159. data/lib/pry/test/helper.rb +0 -170
@@ -1,49 +1,55 @@
1
- module Pry::Command::Ls::JRubyHacks
1
+ # frozen_string_literal: true
2
2
 
3
- private
3
+ class Pry
4
+ class Command
5
+ class Ls < Pry::ClassCommand
6
+ module JRubyHacks
7
+ private
4
8
 
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
9
+ # JRuby creates lots of aliases for methods imported from java in an attempt
10
+ # to make life easier for ruby programmers. (e.g. getFooBar becomes
11
+ # get_foo_bar and foo_bar, and maybe foo_bar? if it returns a Boolean). The
12
+ # full transformations are in the assignAliases method of:
13
+ # https://github.com/jruby/jruby/blob/master/src/org/jruby/javasupport/JavaClass.java
14
+ #
15
+ # This has the unfortunate side-effect of making the output of ls even more
16
+ # incredibly verbose than it normally would be for these objects; and so we
17
+ # filter out all but the nicest of these aliases here.
18
+ #
19
+ # TODO: This is a little bit vague, better heuristics could be used.
20
+ # JRuby also has a lot of scala-specific logic, which we don't copy.
21
+ def trim_jruby_aliases(methods)
22
+ grouped = methods.group_by do |m|
23
+ m.name.sub(/\A(is|get|set)(?=[A-Z_])/, '').gsub(/[_?=]/, '').downcase
24
+ end
21
25
 
22
- grouped.map do |key, values|
23
- values = values.sort_by do |m|
24
- rubbishness(m.name)
25
- end
26
+ grouped.flat_map do |_key, values|
27
+ values = values.sort_by do |m|
28
+ rubbishness(m.name)
29
+ end
26
30
 
27
- found = []
28
- values.select do |x|
29
- (!found.any? { |y| x == y }) && found << x
30
- end
31
- end.flatten(1)
32
- end
31
+ found = []
32
+ values.select do |x|
33
+ (found.none? { |y| x == y }) && found << x
34
+ end
35
+ end
36
+ end
33
37
 
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
38
+ # When removing jruby aliases, we want to keep the alias that is
39
+ # "least rubbish" according to this metric.
40
+ def rubbishness(name)
41
+ name.each_char.map do |x|
42
+ case x
43
+ when /[A-Z]/
44
+ 1
45
+ when '?', '=', '!'
46
+ -2
47
+ else
48
+ 0
49
+ end
50
+ end.inject(&:+) + (name.size / 100.0)
51
+ end
45
52
  end
46
- }.inject(&:+) + (name.size / 100.0)
53
+ end
47
54
  end
48
-
49
55
  end
@@ -1,35 +1,37 @@
1
- class Pry
2
- class Command::Ls < Pry::ClassCommand
3
- class LocalNames < Pry::Command::Ls::Formatter
1
+ # frozen_string_literal: true
4
2
 
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
3
+ class Pry
4
+ class Command
5
+ class Ls < Pry::ClassCommand
6
+ class LocalNames < Pry::Command::Ls::Formatter
7
+ def initialize(no_user_opts, args, pry_instance)
8
+ super(pry_instance)
9
+ @no_user_opts = no_user_opts
10
+ @args = args
11
+ @sticky_locals = pry_instance.sticky_locals
12
+ end
11
13
 
12
- def correct_opts?
13
- super || (@no_user_opts && @args.empty?)
14
- end
14
+ def correct_opts?
15
+ super || (@no_user_opts && @args.empty?)
16
+ end
15
17
 
16
- def output_self
17
- local_vars = grep.regexp[@target.eval('local_variables')]
18
- output_section('locals', format(local_vars))
19
- end
18
+ def output_self
19
+ local_vars = grep.regexp[@target.eval('local_variables')]
20
+ output_section('locals', format(local_vars))
21
+ end
20
22
 
21
- private
23
+ private
22
24
 
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)
25
+ def format(locals)
26
+ locals.sort_by(&:downcase).map do |name|
27
+ if @sticky_locals.include?(name.to_sym)
28
+ color(:pry_var, name)
29
+ else
30
+ color(:local_var, name)
31
+ end
29
32
  end
30
33
  end
31
34
  end
32
-
33
35
  end
34
36
  end
35
37
  end
@@ -1,39 +1,47 @@
1
- class Pry
2
- class Command::Ls < Pry::ClassCommand
3
- class LocalVars < Pry::Command::Ls::Formatter
1
+ # frozen_string_literal: true
4
2
 
5
- def initialize(opts, _pry_)
6
- super(_pry_)
7
- @default_switch = opts[:locals]
8
- @sticky_locals = _pry_.sticky_locals
9
- end
3
+ class Pry
4
+ class Command
5
+ class Ls < Pry::ClassCommand
6
+ class LocalVars < Pry::Command::Ls::Formatter
7
+ def initialize(opts, pry_instance)
8
+ super(pry_instance)
9
+ @default_switch = opts[:locals]
10
+ @sticky_locals = pry_instance.sticky_locals
11
+ end
10
12
 
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
13
+ def output_self
14
+ locals = @target.eval('local_variables').reject do |e|
15
+ @sticky_locals.key?(e.to_sym)
16
+ end
17
+ name_value_pairs = locals.map do |name|
18
+ [name, @target.eval(name.to_s)]
19
+ end
20
+ format(name_value_pairs).join('')
21
+ end
19
22
 
20
- private
23
+ private
21
24
 
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
25
+ def format(name_value_pairs)
26
+ sorted = name_value_pairs.sort_by do |_name, value|
27
+ value.to_s.size
28
+ end
29
+ sorted.reverse.map do |name, value|
30
+ colorized_assignment_style(name, format_value(value))
31
+ end
32
+ end
29
33
 
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]
34
+ def colorized_assignment_style(lhs, rhs, desired_width = 7)
35
+ colorized_lhs = color(:local_var, lhs)
36
+ color_escape_padding = colorized_lhs.size - lhs.size
37
+ pad = desired_width + color_escape_padding
38
+ Kernel.format(
39
+ "%-#{pad}<name>s = %<value>s",
40
+ name: color(:local_var, colorized_lhs),
41
+ value: rhs
42
+ )
43
+ end
35
44
  end
36
-
37
45
  end
38
46
  end
39
47
  end
@@ -1,69 +1,64 @@
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'
1
+ # frozen_string_literal: true
10
2
 
11
3
  class Pry
12
- class Command::Ls < Pry::ClassCommand
4
+ class Command
5
+ class Ls < Pry::ClassCommand
6
+ class LsEntity
7
+ attr_reader :pry_instance
13
8
 
14
- class LsEntity
15
- attr_reader :_pry_
9
+ def initialize(opts)
10
+ @interrogatee = opts[:interrogatee]
11
+ @no_user_opts = opts[:no_user_opts]
12
+ @opts = opts[:opts]
13
+ @args = opts[:args]
14
+ @grep = Grep.new(Regexp.new(opts[:opts][:G] || '.'))
15
+ @pry_instance = opts.delete(:pry_instance)
16
+ end
16
17
 
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
18
+ def entities_table
19
+ entities.map(&:write_out).select { |o| o }.join('')
20
+ end
25
21
 
26
- def entities_table
27
- entities.map(&:write_out).reject { |o| !o }.join('')
28
- end
22
+ private
29
23
 
30
- private
24
+ def grep(entity)
25
+ entity.tap { |o| o.grep = @grep }
26
+ end
31
27
 
32
- def grep(entity)
33
- entity.tap { |o| o.grep = @grep }
34
- end
28
+ def globals
29
+ grep Globals.new(@opts, pry_instance)
30
+ end
35
31
 
36
- def globals
37
- grep Globals.new(@opts, _pry_)
38
- end
32
+ def constants
33
+ grep Constants.new(@interrogatee, @no_user_opts, @opts, pry_instance)
34
+ end
39
35
 
40
- def constants
41
- grep Constants.new(@interrogatee, @no_user_opts, @opts, _pry_)
42
- end
36
+ def methods
37
+ grep(Methods.new(@interrogatee, @no_user_opts, @opts, pry_instance))
38
+ end
43
39
 
44
- def methods
45
- grep(Methods.new(@interrogatee, @no_user_opts, @opts, _pry_))
46
- end
40
+ def self_methods
41
+ grep SelfMethods.new(@interrogatee, @no_user_opts, @opts, pry_instance)
42
+ end
47
43
 
48
- def self_methods
49
- grep SelfMethods.new(@interrogatee, @no_user_opts, @opts, _pry_)
50
- end
44
+ def instance_vars
45
+ grep InstanceVars.new(@interrogatee, @no_user_opts, @opts, pry_instance)
46
+ end
51
47
 
52
- def instance_vars
53
- grep InstanceVars.new(@interrogatee, @no_user_opts, @opts, _pry_)
54
- end
48
+ def local_names
49
+ grep LocalNames.new(@no_user_opts, @args, pry_instance)
50
+ end
55
51
 
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
52
+ def local_vars
53
+ LocalVars.new(@opts, pry_instance)
54
+ end
63
55
 
64
- def entities
65
- [globals, constants, methods, self_methods, instance_vars, local_names,
66
- local_vars]
56
+ def entities
57
+ [
58
+ globals, constants, methods, self_methods, instance_vars, local_names,
59
+ local_vars
60
+ ]
61
+ end
67
62
  end
68
63
  end
69
64
  end
@@ -1,57 +1,55 @@
1
- require 'pry/commands/ls/methods_helper'
2
- require 'pry/commands/ls/interrogatable'
1
+ # frozen_string_literal: true
3
2
 
4
3
  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('')
4
+ class Command
5
+ class Ls < Pry::ClassCommand
6
+ class Methods < Pry::Command::Ls::Formatter
7
+ include Pry::Command::Ls::Interrogatable
8
+ include Pry::Command::Ls::MethodsHelper
9
+
10
+ def initialize(interrogatee, no_user_opts, opts, pry_instance)
11
+ super(pry_instance)
12
+ @interrogatee = interrogatee
13
+ @no_user_opts = no_user_opts
14
+ @default_switch = opts[:methods]
15
+ @instance_methods_switch = opts['instance-methods']
16
+ @ppp_switch = opts[:ppp]
17
+ @jruby_switch = opts['all-java']
18
+ @quiet_switch = opts[:quiet]
19
+ @verbose_switch = opts[:verbose]
20
+ end
21
+
22
+ def output_self
23
+ methods = all_methods.group_by(&:owner)
24
+ # Reverse the resolution order so that the most useful information
25
+ # appears right by the prompt.
26
+ resolution_order.take_while(&below_ceiling).reverse.map do |klass|
27
+ methods_here = (methods[klass] || []).select { |m| grep.regexp[m.name] }
28
+ heading = "#{Pry::WrappedModule.new(klass).method_prefix}methods"
29
+ output_section(heading, format(methods_here))
30
+ end.join('')
31
+ end
32
+
33
+ private
34
+
35
+ def correct_opts?
36
+ super || @instance_methods_switch || @ppp_switch || @no_user_opts
37
+ end
38
+
39
+ # Get a lambda that can be used with `take_while` to prevent over-eager
40
+ # traversal of the Object's ancestry graph.
41
+ def below_ceiling
42
+ ceiling = if @quiet_switch
43
+ [Pry::Method.safe_send(interrogatee_mod, :ancestors)[1]] +
44
+ pry_instance.config.ls.ceiling
45
+ elsif @verbose_switch
46
+ []
47
+ else
48
+ pry_instance.config.ls.ceiling.dup
49
+ end
50
+ ->(klass) { !ceiling.include?(klass) }
51
+ end
32
52
  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
53
  end
56
54
  end
57
55
  end
@@ -1,46 +1,50 @@
1
- require 'pry/commands/ls/jruby_hacks'
2
-
3
- module Pry::Command::Ls::MethodsHelper
4
-
5
- include Pry::Command::Ls::JRubyHacks
6
-
7
- private
8
-
9
- # Get all the methods that we'll want to output.
10
- def all_methods(instance_methods = false)
11
- methods = if instance_methods || @instance_methods_switch
12
- Pry::Method.all_from_class(@interrogatee)
13
- else
14
- Pry::Method.all_from_obj(@interrogatee)
15
- end
16
-
17
- if Pry::Helpers::BaseHelpers.jruby? && !@jruby_switch
18
- methods = trim_jruby_aliases(methods)
19
- end
20
-
21
- methods.select { |method| @ppp_switch || method.visibility == :public }
22
- end
23
-
24
- def resolution_order
25
- if @instance_methods_switch
26
- Pry::Method.instance_resolution_order(@interrogatee)
27
- else
28
- Pry::Method.resolution_order(@interrogatee)
29
- end
30
- end
31
-
32
- def format(methods)
33
- methods.sort_by(&:name).map do |method|
34
- if method.name == 'method_missing'
35
- color(:method_missing, 'method_missing')
36
- elsif method.visibility == :private
37
- color(:private_method, method.name)
38
- elsif method.visibility == :protected
39
- color(:protected_method, method.name)
40
- else
41
- color(:public_method, method.name)
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ class Command
5
+ class Ls < Pry::ClassCommand
6
+ module MethodsHelper
7
+ include Pry::Command::Ls::JRubyHacks
8
+
9
+ private
10
+
11
+ # Get all the methods that we'll want to output.
12
+ def all_methods(instance_methods = false)
13
+ methods = if instance_methods || @instance_methods_switch
14
+ Pry::Method.all_from_class(@interrogatee)
15
+ else
16
+ Pry::Method.all_from_obj(@interrogatee)
17
+ end
18
+
19
+ if Pry::Helpers::Platform.jruby? && !@jruby_switch
20
+ methods = trim_jruby_aliases(methods)
21
+ end
22
+
23
+ methods.select { |method| @ppp_switch || method.visibility == :public }
24
+ end
25
+
26
+ def resolution_order
27
+ if @instance_methods_switch
28
+ Pry::Method.instance_resolution_order(@interrogatee)
29
+ else
30
+ Pry::Method.resolution_order(@interrogatee)
31
+ end
32
+ end
33
+
34
+ def format(methods)
35
+ methods.sort_by(&:name).map do |method|
36
+ if method.name == 'method_missing'
37
+ color(:method_missing, 'method_missing')
38
+ elsif method.visibility == :private
39
+ color(:private_method, method.name)
40
+ elsif method.visibility == :protected
41
+ color(:protected_method, method.name)
42
+ else
43
+ color(:public_method, method.name)
44
+ end
45
+ end
46
+ end
42
47
  end
43
48
  end
44
49
  end
45
-
46
50
  end
@@ -1,32 +1,34 @@
1
- require 'pry/commands/ls/interrogatable'
2
- require 'pry/commands/ls/methods_helper'
1
+ # frozen_string_literal: true
3
2
 
4
3
  class Pry
5
- class Command::Ls < Pry::ClassCommand
6
- class SelfMethods < Pry::Command::Ls::Formatter
7
- include Pry::Command::Ls::Interrogatable
8
- include Pry::Command::Ls::MethodsHelper
4
+ class Command
5
+ class Ls < Pry::ClassCommand
6
+ class SelfMethods < Pry::Command::Ls::Formatter
7
+ include Pry::Command::Ls::Interrogatable
8
+ include Pry::Command::Ls::MethodsHelper
9
9
 
10
- def initialize(interrogatee, no_user_opts, opts, _pry_)
11
- super(_pry_)
12
- @interrogatee = interrogatee
13
- @no_user_opts = no_user_opts
14
- end
10
+ def initialize(interrogatee, no_user_opts, opts, pry_instance)
11
+ super(pry_instance)
12
+ @interrogatee = interrogatee
13
+ @no_user_opts = no_user_opts
14
+ @ppp_switch = opts[:ppp]
15
+ @jruby_switch = opts['all-java']
16
+ end
15
17
 
16
- def output_self
17
- methods = all_methods(true).select do |m|
18
- m.owner == @interrogatee && grep.regexp[m.name]
18
+ def output_self
19
+ methods = all_methods(true).select do |m|
20
+ m.owner == @interrogatee && grep.regexp[m.name]
21
+ end
22
+ heading = "#{Pry::WrappedModule.new(@interrogatee).method_prefix}methods"
23
+ output_section(heading, format(methods))
19
24
  end
20
- heading = "#{ Pry::WrappedModule.new(@interrogatee).method_prefix }methods"
21
- output_section(heading, format(methods))
22
- end
23
25
 
24
- private
26
+ private
25
27
 
26
- def correct_opts?
27
- @no_user_opts && interrogating_a_module?
28
+ def correct_opts?
29
+ @no_user_opts && interrogating_a_module?
30
+ end
28
31
  end
29
-
30
32
  end
31
33
  end
32
34
  end