pry 0.11.3-java → 0.12.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +139 -1
  3. data/LICENSE +1 -1
  4. data/README.md +13 -30
  5. data/bin/pry +0 -4
  6. data/lib/pry.rb +17 -47
  7. data/lib/pry/cli.rb +17 -24
  8. data/lib/pry/code.rb +6 -6
  9. data/lib/pry/code/code_file.rb +5 -4
  10. data/lib/pry/code/code_range.rb +3 -3
  11. data/lib/pry/code/loc.rb +14 -8
  12. data/lib/pry/code_object.rb +4 -4
  13. data/lib/pry/color_printer.rb +1 -0
  14. data/lib/pry/command.rb +36 -29
  15. data/lib/pry/command_set.rb +17 -52
  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.rb +7 -6
  19. data/lib/pry/commands/cat/exception_formatter.rb +9 -8
  20. data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
  21. data/lib/pry/commands/change_prompt.rb +29 -9
  22. data/lib/pry/commands/clear_screen.rb +14 -0
  23. data/lib/pry/commands/code_collector.rb +9 -9
  24. data/lib/pry/commands/easter_eggs.rb +3 -3
  25. data/lib/pry/commands/edit.rb +8 -7
  26. data/lib/pry/commands/exit.rb +2 -1
  27. data/lib/pry/commands/find_method.rb +11 -13
  28. data/lib/pry/commands/gem_cd.rb +1 -1
  29. data/lib/pry/commands/gem_install.rb +2 -2
  30. data/lib/pry/commands/gem_list.rb +2 -2
  31. data/lib/pry/commands/gem_open.rb +1 -1
  32. data/lib/pry/commands/gem_search.rb +2 -2
  33. data/lib/pry/commands/gem_stats.rb +83 -0
  34. data/lib/pry/commands/gist.rb +7 -6
  35. data/lib/pry/commands/help.rb +3 -3
  36. data/lib/pry/commands/hist.rb +9 -8
  37. data/lib/pry/commands/import_set.rb +2 -1
  38. data/lib/pry/commands/install_command.rb +7 -6
  39. data/lib/pry/commands/list_inspectors.rb +2 -2
  40. data/lib/pry/commands/ls.rb +27 -30
  41. data/lib/pry/commands/ls/constants.rb +4 -4
  42. data/lib/pry/commands/ls/formatter.rb +3 -2
  43. data/lib/pry/commands/ls/globals.rb +0 -2
  44. data/lib/pry/commands/ls/grep.rb +0 -2
  45. data/lib/pry/commands/ls/instance_vars.rb +0 -1
  46. data/lib/pry/commands/ls/local_names.rb +0 -2
  47. data/lib/pry/commands/ls/local_vars.rb +0 -2
  48. data/lib/pry/commands/ls/ls_entity.rb +0 -1
  49. data/lib/pry/commands/ls/methods.rb +0 -3
  50. data/lib/pry/commands/ls/methods_helper.rb +1 -1
  51. data/lib/pry/commands/ls/self_methods.rb +0 -1
  52. data/lib/pry/commands/play.rb +1 -2
  53. data/lib/pry/commands/pry_backtrace.rb +1 -1
  54. data/lib/pry/commands/raise_up.rb +2 -1
  55. data/lib/pry/commands/ri.rb +5 -4
  56. data/lib/pry/commands/shell_command.rb +3 -2
  57. data/lib/pry/commands/shell_mode.rb +6 -6
  58. data/lib/pry/commands/show_doc.rb +5 -7
  59. data/lib/pry/commands/show_info.rb +25 -18
  60. data/lib/pry/commands/show_source.rb +5 -2
  61. data/lib/pry/commands/stat.rb +1 -1
  62. data/lib/pry/commands/watch_expression.rb +9 -7
  63. data/lib/pry/commands/whereami.rb +4 -4
  64. data/lib/pry/commands/wtf.rb +15 -2
  65. data/lib/pry/config.rb +33 -9
  66. data/lib/pry/config/behavior.rb +229 -205
  67. data/lib/pry/config/convenience.rb +24 -21
  68. data/lib/pry/config/default.rb +153 -143
  69. data/lib/pry/config/memoization.rb +41 -37
  70. data/lib/pry/core_extensions.rb +4 -3
  71. data/lib/pry/editor.rb +5 -12
  72. data/lib/pry/exceptions.rb +0 -2
  73. data/lib/pry/helpers.rb +1 -0
  74. data/lib/pry/helpers/base_helpers.rb +133 -4
  75. data/lib/pry/helpers/command_helpers.rb +5 -4
  76. data/lib/pry/helpers/documentation_helpers.rb +2 -2
  77. data/lib/pry/helpers/options_helpers.rb +5 -5
  78. data/lib/pry/helpers/platform.rb +58 -0
  79. data/lib/pry/helpers/table.rb +20 -15
  80. data/lib/pry/helpers/text.rb +3 -4
  81. data/lib/pry/history.rb +21 -8
  82. data/lib/pry/hooks.rb +3 -3
  83. data/lib/pry/indent.rb +15 -17
  84. data/lib/pry/input_completer.rb +12 -7
  85. data/lib/pry/input_lock.rb +0 -2
  86. data/lib/pry/last_exception.rb +1 -1
  87. data/lib/pry/method.rb +37 -31
  88. data/lib/pry/method/disowned.rb +2 -1
  89. data/lib/pry/method/patcher.rb +2 -2
  90. data/lib/pry/method/weird_method_locator.rb +7 -8
  91. data/lib/pry/object_path.rb +5 -4
  92. data/lib/pry/output.rb +3 -2
  93. data/lib/pry/pager.rb +4 -3
  94. data/lib/pry/platform.rb +79 -81
  95. data/lib/pry/plugins.rb +7 -3
  96. data/lib/pry/prompt.rb +144 -25
  97. data/lib/pry/pry_class.rb +53 -29
  98. data/lib/pry/pry_instance.rb +88 -55
  99. data/lib/pry/repl.rb +33 -4
  100. data/lib/pry/repl_file_loader.rb +1 -2
  101. data/lib/pry/ring.rb +84 -0
  102. data/lib/pry/rubygem.rb +6 -6
  103. data/lib/pry/slop.rb +17 -17
  104. data/lib/pry/slop/commands.rb +3 -4
  105. data/lib/pry/slop/option.rb +19 -21
  106. data/lib/pry/terminal.rb +2 -1
  107. data/lib/pry/testable/mockable.rb +2 -2
  108. data/lib/pry/testable/pry_tester.rb +1 -1
  109. data/lib/pry/testable/utility.rb +2 -2
  110. data/lib/pry/testable/variables.rb +1 -1
  111. data/lib/pry/version.rb +1 -1
  112. data/lib/pry/wrapped_module.rb +15 -15
  113. data/lib/pry/wrapped_module/candidate.rb +2 -2
  114. metadata +19 -31
  115. data/lib/pry/commands/list_prompts.rb +0 -35
  116. data/lib/pry/commands/simple_prompt.rb +0 -22
  117. data/lib/pry/history_array.rb +0 -121
  118. data/lib/pry/rbx_path.rb +0 -22
@@ -49,7 +49,7 @@ class Pry
49
49
 
50
50
  # Clear the line before starting Pry. This fixes issue #566.
51
51
  if pry.config.correct_indent
52
- Kernel.print Pry::Helpers::BaseHelpers.windows_ansi? ? "\e[0F" : "\e[0G"
52
+ Kernel.print(Helpers::Platform.windows_ansi? ? "\e[0F" : "\e[0G")
53
53
  end
54
54
  end
55
55
 
@@ -106,8 +106,9 @@ class Pry
106
106
 
107
107
  if output.tty? && pry.config.correct_indent && Pry::Helpers::BaseHelpers.use_ansi_codes?
108
108
  output.print @indent.correct_indentation(
109
- current_prompt, indented_val,
110
- original_val.length - indented_val.length
109
+ current_prompt,
110
+ indented_val,
111
+ calculate_overhang(current_prompt, original_val, indented_val)
111
112
  )
112
113
  output.flush
113
114
  end
@@ -218,15 +219,43 @@ class Pry
218
219
  # % pry | tee log
219
220
  def piping?
220
221
  return false unless $stdout.respond_to?(:tty?)
221
- !$stdout.tty? && $stdin.tty? && !Pry::Helpers::BaseHelpers.windows?
222
+
223
+ !$stdout.tty? && $stdin.tty? && !Helpers::Platform.windows?
222
224
  end
223
225
 
224
226
  # @return [void]
225
227
  def set_readline_output
226
228
  return if @readline_output
229
+
227
230
  if piping?
228
231
  @readline_output = (Readline.output = Pry.config.output)
229
232
  end
230
233
  end
234
+
235
+ # Calculates correct overhang for current line. Supports vi Readline
236
+ # mode and its indicators such as "(ins)" or "(cmd)".
237
+ #
238
+ # @return [Integer]
239
+ # @note This doesn't calculate overhang for Readline's emacs mode with an
240
+ # indicator because emacs is the default mode and it doesn't use
241
+ # indicators in 99% of cases.
242
+ def calculate_overhang(current_prompt, original_val, indented_val)
243
+ overhang = original_val.length - indented_val.length
244
+
245
+ if readline_available? && Readline.respond_to?(:vi_editing_mode?)
246
+ begin
247
+ # rb-readline doesn't support this method:
248
+ # https://github.com/ConnorAtherton/rb-readline/issues/152
249
+ if Readline.vi_editing_mode?
250
+ overhang += current_prompt.length - indented_val.length
251
+ end
252
+ rescue NotImplementedError
253
+ # VI editing mode is unsupported on JRuby.
254
+ # https://github.com/pry/pry/issues/1840
255
+ nil
256
+ end
257
+ end
258
+ [0, overhang].max
259
+ end
231
260
  end
232
261
  end
@@ -1,5 +1,4 @@
1
1
  class Pry
2
-
3
2
  # A class to manage the loading of files through the REPL loop.
4
3
  # This is an interesting trick as it processes your file as if it
5
4
  # was user input in an interactive session. As a result, all Pry
@@ -42,7 +41,7 @@ class Pry
42
41
  end
43
42
 
44
43
  content.lines.each do |line|
45
- break unless _pry_.eval line, :generated => true
44
+ break unless _pry_.eval line, generated: true
46
45
  end
47
46
 
48
47
  unless _pry_.eval_string.empty?
@@ -0,0 +1,84 @@
1
+ class Pry
2
+ # A ring is a thread-safe fixed-capacity array to which you can only add
3
+ # elements. Older entries are overwritten as you add new elements, so that the
4
+ # ring can never contain more than `max_size` elemens.
5
+ #
6
+ # @example
7
+ # ring = Pry::Ring.new(3)
8
+ # ring << 1 << 2 << 3
9
+ # ring.to_a #=> [1, 2, 3]
10
+ # ring << 4
11
+ # ring.to_a #=> [2, 3, 4]
12
+ #
13
+ # ring[0] #=> 2
14
+ # ring[-1] #=> 4
15
+ # ring.clear
16
+ # ring[0] #=> nil
17
+ #
18
+ # @api public
19
+ # @since v0.12.0
20
+ class Ring
21
+ # @return [Integer] maximum buffer size
22
+ attr_reader :max_size
23
+
24
+ # @return [Integer] how many objects were added during the lifetime of the
25
+ # ring
26
+ attr_reader :count
27
+ alias size count
28
+
29
+ # @param [Integer] max_size Maximum buffer size. The buffer will start
30
+ # overwriting elements once its reaches its maximum capacity
31
+ def initialize(max_size)
32
+ @max_size = max_size
33
+ @mutex = Mutex.new
34
+ clear
35
+ end
36
+
37
+ # Push `value` to the current index.
38
+ #
39
+ # @param [Object] value
40
+ # @return [self]
41
+ def <<(value)
42
+ @mutex.synchronize do
43
+ @buffer[count % max_size] = value
44
+ @count += 1
45
+ self
46
+ end
47
+ end
48
+
49
+ # Read the value stored at `index`.
50
+ #
51
+ # @param [Integer, Range] index The element (if Integer) or elements
52
+ # (if Range) associated with `index`
53
+ # @return [Object, Array<Object>, nil] element(s) at `index`, `nil` if none
54
+ # exist
55
+ def [](index)
56
+ @mutex.synchronize do
57
+ return @buffer[(count + index) % max_size] if index.is_a?(Integer)
58
+ return @buffer[index] if count <= max_size
59
+
60
+ # Swap parts of array when the array turns page and starts overwriting
61
+ # from the beginning, then apply the range.
62
+ last_part = @buffer.slice([index.end, max_size - 1].min, count % max_size)
63
+ (last_part + (@buffer - last_part))[index]
64
+ end
65
+ end
66
+
67
+ # @return [Array<Object>] the buffer as unwinded array
68
+ def to_a
69
+ return @buffer.dup if count <= max_size
70
+
71
+ last_part = @buffer.slice(count % max_size, @buffer.size)
72
+ last_part + (@buffer - last_part)
73
+ end
74
+
75
+ # Clear the buffer and reset count.
76
+ # @return [void]
77
+ def clear
78
+ @mutex.synchronize do
79
+ @buffer = []
80
+ @count = 0
81
+ end
82
+ end
83
+ end
84
+ end
@@ -23,7 +23,7 @@ class Pry
23
23
  Gem.source_index.find_name(name)
24
24
  end
25
25
 
26
- first_spec = specs.sort_by{ |spec| Gem::Version.new(spec.version) }.last
26
+ first_spec = specs.sort_by { |spec| Gem::Version.new(spec.version) }.last
27
27
 
28
28
  first_spec or raise CommandError, "Gem `#{name}` not found"
29
29
  end
@@ -34,9 +34,9 @@ class Pry
34
34
  # @return [Array<Gem::Specification>]
35
35
  def list(pattern = /.*/)
36
36
  if Gem::Specification.respond_to?(:each)
37
- Gem::Specification.select{|spec| spec.name =~ pattern }
37
+ Gem::Specification.select { |spec| spec.name =~ pattern }
38
38
  else
39
- Gem.source_index.gems.values.select{|spec| spec.name =~ pattern }
39
+ Gem.source_index.gems.values.select { |spec| spec.name =~ pattern }
40
40
  end
41
41
  end
42
42
 
@@ -67,14 +67,14 @@ class Pry
67
67
  else
68
68
  Gem.user_dir
69
69
  end
70
- installer = Gem::DependencyInstaller.new(:install_dir => destination)
70
+ installer = Gem::DependencyInstaller.new(install_dir: destination)
71
71
  installer.install(name)
72
72
  rescue Errno::EACCES
73
73
  raise CommandError,
74
- "Insufficient permissions to install #{ Pry::Helpers::Text.green(name) }."
74
+ "Insufficient permissions to install #{green(name)}."
75
75
  rescue Gem::GemNotFoundException
76
76
  raise CommandError,
77
- "Gem #{ Pry::Helpers::Text.green(name) } not found. Aborting installation."
77
+ "Gem #{green(name)} not found. Aborting installation."
78
78
  else
79
79
  Gem.refresh
80
80
  end
@@ -24,19 +24,18 @@ class Pry::Slop
24
24
 
25
25
  # Returns a default Hash of configuration options this Slop instance uses.
26
26
  DEFAULT_OPTIONS = {
27
- :strict => false,
28
- :help => false,
29
- :banner => nil,
30
- :ignore_case => false,
31
- :autocreate => false,
32
- :arguments => false,
33
- :optional_arguments => false,
34
- :multiple_switches => true,
35
- :longest_flag => 0
27
+ strict: false,
28
+ help: false,
29
+ banner: nil,
30
+ ignore_case: false,
31
+ autocreate: false,
32
+ arguments: false,
33
+ optional_arguments: false,
34
+ multiple_switches: true,
35
+ longest_flag: 0
36
36
  }
37
37
 
38
38
  class << self
39
-
40
39
  # items - The Array of items to extract options from (default: ARGV).
41
40
  # config - The Hash of configuration options to send to Slop.new().
42
41
  # block - An optional block used to add options.
@@ -106,7 +105,6 @@ class Pry::Slop
106
105
 
107
106
  opts
108
107
  end
109
-
110
108
  end
111
109
 
112
110
  # The Hash of configuration options for this Slop instance.
@@ -135,7 +133,7 @@ class Pry::Slop
135
133
  end
136
134
 
137
135
  if config[:help]
138
- on('-h', '--help', 'Display this help message.', :tail => true) do
136
+ on('-h', '--help', 'Display this help message.', tail: true) do
139
137
  $stderr.puts help
140
138
  end
141
139
  end
@@ -217,7 +215,7 @@ class Pry::Slop
217
215
  return items
218
216
  end
219
217
 
220
- if cmd = @commands[items[0]]
218
+ if (cmd = @commands[items[0]])
221
219
  return cmd.parse! items[1..-1]
222
220
  end
223
221
 
@@ -332,7 +330,7 @@ class Pry::Slop
332
330
  # Override this method so we can check if an option? method exists.
333
331
  #
334
332
  # Returns true if this option key exists in our list of options.
335
- def respond_to_missing?(method_name, include_all=false)
333
+ def respond_to_missing?(method_name, include_all = false)
336
334
  options.any? { |o| o.key == method_name.to_s.chop } || super
337
335
  end
338
336
 
@@ -464,7 +462,8 @@ class Pry::Slop
464
462
  #
465
463
  # Returns nothing.
466
464
  def process_item(items, index, &block)
467
- return unless item = items[index]
465
+ return unless (item = items[index])
466
+
468
467
  option, argument = extract_option(item) if item.start_with?('-')
469
468
 
470
469
  if option
@@ -514,6 +513,7 @@ class Pry::Slop
514
513
  if config[:multiple_switches] && strict?
515
514
  raise InvalidOptionError, "Unknown option -#{item}"
516
515
  end
516
+
517
517
  return
518
518
  end
519
519
 
@@ -544,7 +544,8 @@ class Pry::Slop
544
544
  def execute_multiple_switches(option, argument, index)
545
545
  execute_option(option, nil, index)
546
546
  argument.split('').each do |key|
547
- next unless opt = fetch_option(key)
547
+ next unless (opt = fetch_option(key))
548
+
548
549
  opt.count += 1
549
550
  execute_option(opt, nil, index, key)
550
551
  end
@@ -657,5 +658,4 @@ class Pry::Slop
657
658
  " #{cmd}#{' ' * (padding - cmd.size)} #{opts.description}"
658
659
  end.join("\n")
659
660
  end
660
-
661
661
  end
@@ -133,13 +133,13 @@ class Pry::Slop
133
133
  #
134
134
  # Returns the original Array of items with options removed.
135
135
  def parse!(items = ARGV)
136
- if opts = commands[items[0].to_s]
136
+ if (opts = commands[items[0].to_s])
137
137
  @triggered_command = items.shift
138
138
  execute_arguments! items
139
139
  opts.parse! items
140
140
  execute_global_opts! items
141
141
  else
142
- if opts = commands['default']
142
+ if (opts = commands['default'])
143
143
  opts.parse! items
144
144
  else
145
145
  if config[:strict] && items[0]
@@ -187,10 +187,9 @@ class Pry::Slop
187
187
 
188
188
  # Returns nothing.
189
189
  def execute_global_opts!(items)
190
- if global_opts = commands['global']
190
+ if (global_opts = commands['global'])
191
191
  global_opts.parse! items
192
192
  end
193
193
  end
194
-
195
194
  end
196
195
  end
@@ -1,20 +1,19 @@
1
1
  class Pry::Slop
2
2
  class Option
3
-
4
3
  # The default Hash of configuration options this class uses.
5
4
  DEFAULT_OPTIONS = {
6
- :argument => false,
7
- :optional_argument => false,
8
- :tail => false,
9
- :default => nil,
10
- :callback => nil,
11
- :delimiter => ',',
12
- :limit => 0,
13
- :match => nil,
14
- :optional => true,
15
- :required => false,
16
- :as => String,
17
- :autocreated => false
5
+ argument: false,
6
+ optional_argument: false,
7
+ tail: false,
8
+ default: nil,
9
+ callback: nil,
10
+ delimiter: ',',
11
+ limit: 0,
12
+ match: nil,
13
+ optional: true,
14
+ required: false,
15
+ as: String,
16
+ autocreated: false
18
17
  }
19
18
 
20
19
  attr_reader :short, :long, :description, :config, :types
@@ -41,12 +40,12 @@ class Pry::Slop
41
40
  @value = nil
42
41
 
43
42
  @types = {
44
- :string => proc { |v| v.to_s },
45
- :symbol => proc { |v| v.to_sym },
46
- :integer => proc { |v| value_to_integer(v) },
47
- :float => proc { |v| value_to_float(v) },
48
- :range => proc { |v| value_to_range(v) },
49
- :count => proc { |v| @count }
43
+ string: proc { |v| v.to_s },
44
+ symbol: proc { |v| v.to_sym },
45
+ integer: proc { |v| value_to_integer(v) },
46
+ float: proc { |v| value_to_float(v) },
47
+ range: proc { |v| value_to_range(v) },
48
+ count: proc { |v| @count }
50
49
  }
51
50
 
52
51
  if long && long.size > @slop.config[:longest_flag]
@@ -114,7 +113,7 @@ class Pry::Slop
114
113
  if type.respond_to?(:call)
115
114
  type.call(value)
116
115
  else
117
- if callable = types[type.to_s.downcase.to_sym]
116
+ if (callable = types[type.to_s.downcase.to_sym])
118
117
  callable.call(value)
119
118
  else
120
119
  value
@@ -203,6 +202,5 @@ class Pry::Slop
203
202
  end
204
203
  end
205
204
  end
206
-
207
205
  end
208
206
  end
@@ -41,7 +41,7 @@ class Pry::Terminal
41
41
  end
42
42
 
43
43
  def screen_size_according_to_io_console
44
- return if Pry::Helpers::BaseHelpers.jruby?
44
+ return if Pry::Helpers::Platform.jruby?
45
45
 
46
46
  begin
47
47
  require 'io/console'
@@ -77,6 +77,7 @@ class Pry::Terminal
77
77
 
78
78
  def screen_size_according_to_ansicon_env
79
79
  return unless ENV['ANSICON'] =~ /\((.*)x(.*)\)/
80
+
80
81
  size = [$2, $1]
81
82
  size if nonzero_column?(size)
82
83
  end
@@ -1,8 +1,8 @@
1
1
  module Pry::Testable::Mockable
2
- def mock_command(cmd, args=[], opts={})
2
+ def mock_command(cmd, args = [], opts = {})
3
3
  output = StringIO.new
4
4
  pry = Pry.new(output: output)
5
- ret = cmd.new(opts.merge(pry_instance: pry, :output => output)).call_safely(*args)
5
+ ret = cmd.new(opts.merge(pry_instance: pry, output: output)).call_safely(*args)
6
6
  Struct.new(:output, :return).new(output.string, ret)
7
7
  end
8
8
 
@@ -4,7 +4,7 @@ class Pry::Testable::PryTester
4
4
  def_delegators :@pry, :eval_string, :eval_string=
5
5
 
6
6
  def initialize(target = TOPLEVEL_BINDING, options = {})
7
- @pry = Pry.new(options.merge(:target => target))
7
+ @pry = Pry.new(options.merge(target: target))
8
8
  @history = options[:history]
9
9
  @pry.inject_sticky_locals!
10
10
  reset_output
@@ -7,7 +7,7 @@ module Pry::Testable::Utility
7
7
  #
8
8
  # @return [void]
9
9
  #
10
- def temp_file(ext='.rb')
10
+ def temp_file(ext = '.rb')
11
11
  file = Tempfile.open(['pry', ext])
12
12
  yield file
13
13
  ensure
@@ -20,7 +20,7 @@ module Pry::Testable::Utility
20
20
 
21
21
  def inner_scope
22
22
  catch(:inner_scope) do
23
- yield ->{ throw(:inner_scope, self) }
23
+ yield -> { throw(:inner_scope, self) }
24
24
  end
25
25
  end
26
26
  end