pry 0.10.3 → 0.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +251 -16
  3. data/LICENSE +1 -1
  4. data/README.md +35 -51
  5. data/bin/pry +3 -11
  6. data/lib/pry/basic_object.rb +6 -0
  7. data/lib/pry/cli.rb +50 -52
  8. data/lib/pry/code/code_file.rb +13 -6
  9. data/lib/pry/code/code_range.rb +3 -3
  10. data/lib/pry/code/loc.rb +14 -8
  11. data/lib/pry/code.rb +12 -5
  12. data/lib/pry/code_object.rb +27 -4
  13. data/lib/pry/color_printer.rb +20 -10
  14. data/lib/pry/command.rb +76 -45
  15. data/lib/pry/command_set.rb +17 -45
  16. data/lib/pry/commands/amend_line.rb +3 -4
  17. data/lib/pry/commands/bang.rb +1 -1
  18. data/lib/pry/commands/cat/exception_formatter.rb +10 -8
  19. data/lib/pry/commands/cat/file_formatter.rb +7 -3
  20. data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
  21. data/lib/pry/commands/cat.rb +7 -6
  22. data/lib/pry/commands/change_prompt.rb +29 -9
  23. data/lib/pry/commands/clear_screen.rb +14 -0
  24. data/lib/pry/commands/code_collector.rb +25 -23
  25. data/lib/pry/commands/easter_eggs.rb +12 -12
  26. data/lib/pry/commands/edit/file_and_line_locator.rb +1 -1
  27. data/lib/pry/commands/edit.rb +15 -10
  28. data/lib/pry/commands/exit.rb +2 -1
  29. data/lib/pry/commands/find_method.rb +12 -14
  30. data/lib/pry/commands/gem_cd.rb +1 -1
  31. data/lib/pry/commands/gem_install.rb +2 -2
  32. data/lib/pry/commands/gem_list.rb +2 -2
  33. data/lib/pry/commands/gem_open.rb +2 -2
  34. data/lib/pry/commands/gem_readme.rb +25 -0
  35. data/lib/pry/commands/gem_search.rb +40 -0
  36. data/lib/pry/commands/gem_stats.rb +83 -0
  37. data/lib/pry/commands/gist.rb +7 -6
  38. data/lib/pry/commands/help.rb +3 -3
  39. data/lib/pry/commands/hist.rb +11 -10
  40. data/lib/pry/commands/import_set.rb +2 -1
  41. data/lib/pry/commands/install_command.rb +7 -6
  42. data/lib/pry/commands/jump_to.rb +7 -7
  43. data/lib/pry/commands/list_inspectors.rb +2 -2
  44. data/lib/pry/commands/ls/constants.rb +14 -3
  45. data/lib/pry/commands/ls/formatter.rb +4 -2
  46. data/lib/pry/commands/ls/globals.rb +0 -2
  47. data/lib/pry/commands/ls/grep.rb +0 -2
  48. data/lib/pry/commands/ls/instance_vars.rb +0 -1
  49. data/lib/pry/commands/ls/jruby_hacks.rb +2 -2
  50. data/lib/pry/commands/ls/local_names.rb +0 -2
  51. data/lib/pry/commands/ls/local_vars.rb +0 -2
  52. data/lib/pry/commands/ls/ls_entity.rb +0 -1
  53. data/lib/pry/commands/ls/methods.rb +0 -3
  54. data/lib/pry/commands/ls/methods_helper.rb +1 -1
  55. data/lib/pry/commands/ls/self_methods.rb +2 -1
  56. data/lib/pry/commands/ls.rb +30 -31
  57. data/lib/pry/commands/play.rb +3 -4
  58. data/lib/pry/commands/pry_backtrace.rb +1 -1
  59. data/lib/pry/commands/raise_up.rb +2 -1
  60. data/lib/pry/commands/reload_code.rb +2 -2
  61. data/lib/pry/commands/ri.rb +9 -4
  62. data/lib/pry/commands/shell_command.rb +36 -9
  63. data/lib/pry/commands/shell_mode.rb +6 -6
  64. data/lib/pry/commands/show_doc.rb +5 -7
  65. data/lib/pry/commands/show_info.rb +41 -20
  66. data/lib/pry/commands/show_source.rb +5 -2
  67. data/lib/pry/commands/stat.rb +1 -1
  68. data/lib/pry/commands/watch_expression/expression.rb +1 -1
  69. data/lib/pry/commands/watch_expression.rb +9 -7
  70. data/lib/pry/commands/whereami.rb +16 -9
  71. data/lib/pry/commands/wtf.rb +15 -2
  72. data/lib/pry/config/behavior.rb +230 -114
  73. data/lib/pry/config/convenience.rb +24 -21
  74. data/lib/pry/config/default.rb +151 -153
  75. data/lib/pry/config/memoization.rb +48 -0
  76. data/lib/pry/config.rb +30 -19
  77. data/lib/pry/core_extensions.rb +15 -4
  78. data/lib/pry/editor.rb +5 -12
  79. data/lib/pry/exceptions.rb +1 -3
  80. data/lib/pry/forwardable.rb +23 -0
  81. data/lib/pry/helpers/base_helpers.rb +197 -110
  82. data/lib/pry/helpers/command_helpers.rb +5 -4
  83. data/lib/pry/helpers/documentation_helpers.rb +3 -2
  84. data/lib/pry/helpers/options_helpers.rb +6 -6
  85. data/lib/pry/helpers/platform.rb +58 -0
  86. data/lib/pry/helpers/table.rb +20 -15
  87. data/lib/pry/helpers/text.rb +82 -74
  88. data/lib/pry/helpers.rb +1 -0
  89. data/lib/pry/history.rb +44 -10
  90. data/lib/pry/hooks.rb +50 -109
  91. data/lib/pry/indent.rb +21 -19
  92. data/lib/pry/input_completer.rb +146 -123
  93. data/lib/pry/input_lock.rb +0 -2
  94. data/lib/pry/last_exception.rb +2 -2
  95. data/lib/pry/method/disowned.rb +3 -1
  96. data/lib/pry/method/patcher.rb +2 -5
  97. data/lib/pry/method/weird_method_locator.rb +21 -11
  98. data/lib/pry/method.rb +44 -38
  99. data/lib/pry/object_path.rb +5 -4
  100. data/lib/pry/output.rb +37 -37
  101. data/lib/pry/pager.rb +195 -181
  102. data/lib/pry/platform.rb +91 -0
  103. data/lib/pry/plugins.rb +27 -8
  104. data/lib/pry/prompt.rb +144 -25
  105. data/lib/pry/pry_class.rb +83 -33
  106. data/lib/pry/pry_instance.rb +94 -59
  107. data/lib/pry/repl.rb +70 -11
  108. data/lib/pry/repl_file_loader.rb +2 -3
  109. data/lib/pry/ring.rb +84 -0
  110. data/lib/pry/rubygem.rb +9 -7
  111. data/lib/pry/slop/LICENSE +20 -0
  112. data/lib/pry/slop/commands.rb +195 -0
  113. data/lib/pry/slop/option.rb +206 -0
  114. data/lib/pry/slop.rb +661 -0
  115. data/lib/pry/terminal.rb +18 -6
  116. data/lib/pry/testable/evalable.rb +15 -0
  117. data/lib/pry/testable/mockable.rb +14 -0
  118. data/lib/pry/testable/pry_tester.rb +73 -0
  119. data/lib/pry/testable/utility.rb +26 -0
  120. data/lib/pry/testable/variables.rb +46 -0
  121. data/lib/pry/testable.rb +70 -0
  122. data/lib/pry/version.rb +1 -1
  123. data/lib/pry/{module_candidate.rb → wrapped_module/candidate.rb} +9 -14
  124. data/lib/pry/wrapped_module.rb +22 -21
  125. data/lib/pry.rb +21 -50
  126. metadata +35 -46
  127. data/lib/pry/commands/list_prompts.rb +0 -35
  128. data/lib/pry/commands/simple_prompt.rb +0 -22
  129. data/lib/pry/history_array.rb +0 -121
  130. data/lib/pry/rbx_path.rb +0 -22
  131. data/lib/pry/test/helper.rb +0 -170
data/lib/pry/method.rb CHANGED
@@ -39,7 +39,7 @@ class Pry
39
39
  # contain any context.
40
40
  # @return [Pry::Method, nil] A `Pry::Method` instance containing the requested
41
41
  # method, or `nil` if name is `nil` or no method could be located matching the parameters.
42
- def from_str(name, target=TOPLEVEL_BINDING, options={})
42
+ def from_str(name, target = TOPLEVEL_BINDING, options = {})
43
43
  if name.nil?
44
44
  nil
45
45
  elsif name.to_s =~ /(.+)\#(\S+)\Z/
@@ -56,8 +56,8 @@ class Pry
56
56
  elsif options[:methods]
57
57
  from_obj(target.eval("self"), name, target)
58
58
  else
59
- from_str(name, target, :instance => true) or
60
- from_str(name, target, :methods => true)
59
+ from_str(name, target, instance: true) or
60
+ from_str(name, target, methods: true)
61
61
  end
62
62
 
63
63
  rescue Pry::RescuableException
@@ -101,7 +101,7 @@ class Pry
101
101
  # @param [Symbol] method_type The type of method: :method or :instance_method
102
102
  # @param [Binding] target The binding where the method is looked up.
103
103
  # @return [Method, UnboundMethod] The 'refined' method object.
104
- def lookup_method_via_binding(obj, method_name, method_type, target=TOPLEVEL_BINDING)
104
+ def lookup_method_via_binding(obj, method_name, method_type, target = TOPLEVEL_BINDING)
105
105
  Pry.current[:obj] = obj
106
106
  Pry.current[:name] = method_name
107
107
  receiver = obj.is_a?(Module) ? "Module" : "Kernel"
@@ -118,7 +118,7 @@ class Pry
118
118
  # @param [String] name
119
119
  # @param [Binding] target The binding where the method is looked up.
120
120
  # @return [Pry::Method, nil]
121
- def from_class(klass, name, target=TOPLEVEL_BINDING)
121
+ def from_class(klass, name, target = TOPLEVEL_BINDING)
122
122
  new(lookup_method_via_binding(klass, name, :instance_method, target)) rescue nil
123
123
  end
124
124
  alias from_module from_class
@@ -131,7 +131,7 @@ class Pry
131
131
  # @param [String] name
132
132
  # @param [Binding] target The binding where the method is looked up.
133
133
  # @return [Pry::Method, nil]
134
- def from_obj(obj, name, target=TOPLEVEL_BINDING)
134
+ def from_obj(obj, name, target = TOPLEVEL_BINDING)
135
135
  new(lookup_method_via_binding(obj, name, :method, target)) rescue nil
136
136
  end
137
137
 
@@ -139,12 +139,12 @@ class Pry
139
139
  # @param [Class,Module] klass
140
140
  # @param [Boolean] include_super Whether to include methods from ancestors.
141
141
  # @return [Array[Pry::Method]]
142
- def all_from_class(klass, include_super=true)
143
- %w(public protected private).map do |visibility|
142
+ def all_from_class(klass, include_super = true)
143
+ %w(public protected private).flat_map do |visibility|
144
144
  safe_send(klass, :"#{visibility}_instance_methods", include_super).map do |method_name|
145
- new(safe_send(klass, :instance_method, method_name), :visibility => visibility.to_sym)
145
+ new(safe_send(klass, :instance_method, method_name), visibility: visibility.to_sym)
146
146
  end
147
- end.flatten(1)
147
+ end
148
148
  end
149
149
 
150
150
  #
@@ -157,16 +157,16 @@ class Pry
157
157
  #
158
158
  # @return [Array[Pry::Method]]
159
159
  #
160
- def all_from_obj(obj, include_super=true)
160
+ def all_from_obj(obj, include_super = true)
161
161
  all_from_class(singleton_class_of(obj), include_super)
162
162
  end
163
163
 
164
164
  #
165
165
  # @deprecated
166
- # please use {#all_from_obj} instead.
166
+ # please use {all_from_obj} instead.
167
167
  # the `method_type` argument is ignored.
168
168
  #
169
- def all_from_common(obj, method_type = nil, include_super=true)
169
+ def all_from_common(obj, _method_type = nil, include_super = true)
170
170
  all_from_obj(obj, include_super)
171
171
  end
172
172
 
@@ -212,9 +212,9 @@ class Pry
212
212
  # the lowest copy will be returned.
213
213
  def singleton_class_resolution_order(klass)
214
214
  ancestors = Pry::Method.safe_send(klass, :ancestors)
215
- resolution_order = ancestors.grep(Class).map do |anc|
215
+ resolution_order = ancestors.grep(Class).flat_map do |anc|
216
216
  [singleton_class_of(anc), *singleton_class_of(anc).included_modules]
217
- end.flatten(1)
217
+ end
218
218
 
219
219
  resolution_order.reverse.uniq.reverse - Class.included_modules
220
220
  end
@@ -233,7 +233,7 @@ class Pry
233
233
  # @param [::Method, UnboundMethod, Proc] method
234
234
  # @param [Hash] known_info Can be used to pre-cache expensive to compute stuff.
235
235
  # @return [Pry::Method]
236
- def initialize(method, known_info={})
236
+ def initialize(method, known_info = {})
237
237
  @method = method
238
238
  @visibility = known_info[:visibility]
239
239
  end
@@ -298,7 +298,8 @@ class Pry
298
298
  # @return [String, nil] The documentation for the method, or `nil` if it's
299
299
  # unavailable.
300
300
  def doc
301
- @doc ||= case source_type
301
+ @doc ||=
302
+ case source_type
302
303
  when :c
303
304
  info = pry_doc_info
304
305
  info.docstring if info
@@ -317,7 +318,7 @@ class Pry
317
318
  # `nil` if the filename is unavailable.
318
319
  def source_file
319
320
  if source_location.nil?
320
- if !rbx? and source_type == :c
321
+ if source_type == :c
321
322
  info = pry_doc_info
322
323
  info.file if info
323
324
  end
@@ -354,20 +355,24 @@ class Pry
354
355
 
355
356
  # @return [String] A representation of the method's signature, including its
356
357
  # name and parameters. Optional and "rest" parameters are marked with `*`
357
- # and block parameters with `&`. If the parameter names are unavailable,
358
- # they're given numbered names instead.
358
+ # and block parameters with `&`. Keyword arguments are shown with `:`
359
+ # If the parameter names are unavailable, they're given numbered names instead.
359
360
  # Paraphrased from `awesome_print` gem.
360
361
  def signature
361
362
  if respond_to?(:parameters)
362
- args = parameters.inject([]) do |arr, (type, name)|
363
- name ||= (type == :block ? 'block' : "arg#{arr.size + 1}")
364
- arr << case type
365
- when :req then name.to_s
366
- when :opt then "#{name}=?"
367
- when :rest then "*#{name}"
368
- when :block then "&#{name}"
369
- else '?'
370
- end
363
+ args = parameters.inject([]) do |args_array, (arg_type, name)|
364
+ name ||= (arg_type == :block ? 'block' : "arg#{args_array.size + 1}")
365
+ args_array.push(
366
+ case arg_type
367
+ when :req then name.to_s
368
+ when :opt then "#{name}=?"
369
+ when :rest then "*#{name}"
370
+ when :block then "&#{name}"
371
+ when :key then "#{name}:?"
372
+ when :keyreq then "#{name}:"
373
+ else '?'
374
+ end
375
+ )
371
376
  end
372
377
  else
373
378
  args = (1..arity.abs).map { |i| "arg#{i}" }
@@ -379,7 +384,7 @@ class Pry
379
384
 
380
385
  # @return [Pry::Method, nil] The wrapped method that is called when you
381
386
  # use "super" in the body of this method.
382
- def super(times=1)
387
+ def super(times = 1)
383
388
  if UnboundMethod === @method
384
389
  sup = super_using_ancestors(Pry::Method.instance_resolution_order(owner), times)
385
390
  else
@@ -393,6 +398,7 @@ class Pry
393
398
  # before any aliasing, or `nil` if it can't be determined.
394
399
  def original_name
395
400
  return nil if source_type != :ruby
401
+
396
402
  method_name_from_first_line(source.lines.first)
397
403
  end
398
404
 
@@ -461,8 +467,8 @@ class Pry
461
467
 
462
468
  # @param [String, Symbol] method_name
463
469
  # @return [Boolean]
464
- def respond_to?(method_name)
465
- super or @method.respond_to?(method_name)
470
+ def respond_to?(method_name, include_all = false)
471
+ super or @method.respond_to?(method_name, include_all)
466
472
  end
467
473
 
468
474
  # Delegate any unknown calls to the wrapped method.
@@ -483,8 +489,8 @@ class Pry
483
489
  Pry::MethodInfo.info_for(@method) or raise CommandError, "Cannot locate this method: #{name}. (source_location returns nil)"
484
490
  else
485
491
  fail_msg = "Cannot locate this method: #{name}."
486
- if mri?
487
- fail_msg += ' Try `gem-install pry-doc` to get access to Ruby Core documentation.'
492
+ if Helpers::Platform.mri?
493
+ fail_msg += " Invoke the 'gem-install pry-doc' Pry command to get access to Ruby Core documentation.\n"
488
494
  end
489
495
  raise CommandError, fail_msg
490
496
  end
@@ -492,7 +498,7 @@ class Pry
492
498
 
493
499
  # @param [Class, Module] ancestors The ancestors to investigate
494
500
  # @return [Method] The unwrapped super-method
495
- def super_using_ancestors(ancestors, times=1)
501
+ def super_using_ancestors(ancestors, times = 1)
496
502
  next_owner = self.owner
497
503
  times.times do
498
504
  i = ancestors.index(next_owner) + 1
@@ -529,9 +535,9 @@ class Pry
529
535
  end
530
536
 
531
537
  def ruby_source
532
- # clone of MethodSource.source_helper that knows to use our
533
- # hacked version of source_location for rbx core methods, and
534
- # our input buffer for methods defined in (pry)
538
+ # Clone of `MethodSource.source_helper` that knows to use our
539
+ # hacked version of `source_location` for our input buffer for methods
540
+ # defined in `(pry)`.
535
541
  file, line = *source_location
536
542
  raise SourceNotFoundError, "Could not locate source for #{name_with_owner}!" unless file
537
543
 
@@ -28,7 +28,7 @@ class Pry
28
28
  stack = @current_stack.dup
29
29
 
30
30
  begin
31
- next_segment = ""
31
+ next_segment = ""
32
32
 
33
33
  loop do
34
34
  # Scan for as long as we don't see a slash
@@ -74,9 +74,10 @@ class Pry
74
74
  "Exception: #{err.inspect}"
75
75
  ].join("\n")
76
76
 
77
- raise CommandError.new(msg).tap { |e|
78
- e.set_backtrace err.backtrace
79
- }
77
+ command_error = CommandError.new(msg)
78
+ command_error.set_backtrace(err.backtrace)
79
+
80
+ raise command_error
80
81
  end
81
82
  end
82
83
  end
data/lib/pry/output.rb CHANGED
@@ -1,50 +1,50 @@
1
- class Pry
2
- class Output
3
- attr_reader :_pry_
1
+ class Pry::Output
2
+ attr_reader :_pry_
4
3
 
5
- def initialize(_pry_)
6
- @_pry_ = _pry_
7
- end
4
+ def initialize(_pry_)
5
+ @_pry_ = _pry_
6
+ @boxed_io = _pry_.config.output
7
+ end
8
8
 
9
- def puts(*objs)
10
- return print "\n" if objs.empty?
9
+ def puts(*objs)
10
+ return print "\n" if objs.empty?
11
11
 
12
- objs.each do |obj|
13
- if ary = Array.try_convert(obj)
14
- puts(*ary)
15
- else
16
- print "#{obj.to_s.chomp}\n"
17
- end
12
+ objs.each do |obj|
13
+ if (ary = Array.try_convert(obj))
14
+ puts(*ary)
15
+ else
16
+ print "#{obj.to_s.chomp}\n"
18
17
  end
19
-
20
- nil
21
18
  end
19
+ nil
20
+ end
22
21
 
23
- def print(*objs)
24
- objs.each do |obj|
25
- _pry_.config.output.print decolorize_maybe(obj.to_s)
26
- end
27
-
28
- nil
22
+ def print(*objs)
23
+ objs.each do |obj|
24
+ @boxed_io.print decolorize_maybe(obj.to_s)
29
25
  end
30
- alias << print
31
- alias write print
26
+ nil
27
+ end
28
+ alias << print
29
+ alias write print
32
30
 
33
- # If _pry_.config.color is currently false, removes ansi escapes from the string.
34
- def decolorize_maybe(str)
35
- if _pry_.config.color
36
- str
37
- else
38
- Helpers::Text.strip_color str
39
- end
40
- end
31
+ def tty?
32
+ @boxed_io.respond_to?(:tty?) and @boxed_io.tty?
33
+ end
41
34
 
42
- def method_missing(name, *args, &block)
43
- _pry_.config.output.send(name, *args, &block)
44
- end
35
+ def method_missing(name, *args, &block)
36
+ @boxed_io.__send__(name, *args, &block)
37
+ end
38
+
39
+ def respond_to_missing?(m, include_all = false)
40
+ @boxed_io.respond_to?(m, include_all)
41
+ end
45
42
 
46
- def respond_to_missing?(*a)
47
- _pry_.config.respond_to?(*a)
43
+ def decolorize_maybe(str)
44
+ if _pry_.config.color
45
+ str
46
+ else
47
+ Pry::Helpers::Text.strip_color str
48
48
  end
49
49
  end
50
50
  end