pry 0.10.4-java → 0.11.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +52 -18
  3. data/LICENSE +1 -1
  4. data/README.md +32 -31
  5. data/bin/pry +3 -7
  6. data/lib/pry.rb +4 -4
  7. data/lib/pry/basic_object.rb +6 -0
  8. data/lib/pry/cli.rb +39 -34
  9. data/lib/pry/code.rb +6 -1
  10. data/lib/pry/code/code_file.rb +8 -2
  11. data/lib/pry/code_object.rb +23 -0
  12. data/lib/pry/color_printer.rb +20 -11
  13. data/lib/pry/command.rb +40 -16
  14. data/lib/pry/command_set.rb +9 -2
  15. data/lib/pry/commands/cat/exception_formatter.rb +11 -10
  16. data/lib/pry/commands/cat/file_formatter.rb +7 -3
  17. data/lib/pry/commands/code_collector.rb +16 -14
  18. data/lib/pry/commands/easter_eggs.rb +9 -9
  19. data/lib/pry/commands/edit.rb +7 -3
  20. data/lib/pry/commands/edit/file_and_line_locator.rb +1 -1
  21. data/lib/pry/commands/find_method.rb +1 -1
  22. data/lib/pry/commands/gem_open.rb +1 -1
  23. data/lib/pry/commands/gem_readme.rb +25 -0
  24. data/lib/pry/commands/gem_search.rb +40 -0
  25. data/lib/pry/commands/hist.rb +2 -2
  26. data/lib/pry/commands/jump_to.rb +7 -7
  27. data/lib/pry/commands/ls.rb +3 -1
  28. data/lib/pry/commands/ls/constants.rb +12 -1
  29. data/lib/pry/commands/ls/formatter.rb +1 -0
  30. data/lib/pry/commands/ls/jruby_hacks.rb +2 -2
  31. data/lib/pry/commands/ls/self_methods.rb +2 -0
  32. data/lib/pry/commands/play.rb +2 -2
  33. data/lib/pry/commands/reload_code.rb +2 -2
  34. data/lib/pry/commands/ri.rb +4 -0
  35. data/lib/pry/commands/shell_command.rb +34 -8
  36. data/lib/pry/commands/show_info.rb +10 -2
  37. data/lib/pry/commands/watch_expression/expression.rb +1 -1
  38. data/lib/pry/commands/whereami.rb +7 -6
  39. data/lib/pry/config.rb +3 -16
  40. data/lib/pry/config/behavior.rb +140 -49
  41. data/lib/pry/config/default.rb +21 -33
  42. data/lib/pry/config/memoization.rb +44 -0
  43. data/lib/pry/core_extensions.rb +12 -2
  44. data/lib/pry/editor.rb +1 -1
  45. data/lib/pry/exceptions.rb +1 -1
  46. data/lib/pry/forwardable.rb +23 -0
  47. data/lib/pry/helpers/base_helpers.rb +6 -10
  48. data/lib/pry/helpers/documentation_helpers.rb +1 -0
  49. data/lib/pry/helpers/options_helpers.rb +1 -1
  50. data/lib/pry/helpers/text.rb +69 -75
  51. data/lib/pry/history.rb +22 -1
  52. data/lib/pry/history_array.rb +1 -1
  53. data/lib/pry/hooks.rb +48 -107
  54. data/lib/pry/indent.rb +6 -2
  55. data/lib/pry/input_completer.rb +138 -120
  56. data/lib/pry/last_exception.rb +2 -2
  57. data/lib/pry/method.rb +15 -15
  58. data/lib/pry/method/disowned.rb +1 -0
  59. data/lib/pry/method/patcher.rb +0 -3
  60. data/lib/pry/output.rb +37 -38
  61. data/lib/pry/pager.rb +11 -8
  62. data/lib/pry/plugins.rb +20 -5
  63. data/lib/pry/pry_class.rb +30 -4
  64. data/lib/pry/pry_instance.rb +8 -6
  65. data/lib/pry/repl.rb +38 -8
  66. data/lib/pry/repl_file_loader.rb +1 -1
  67. data/lib/pry/rubygem.rb +3 -1
  68. data/lib/pry/slop.rb +661 -0
  69. data/lib/pry/slop/LICENSE +20 -0
  70. data/lib/pry/slop/commands.rb +196 -0
  71. data/lib/pry/slop/option.rb +208 -0
  72. data/lib/pry/terminal.rb +16 -5
  73. data/lib/pry/test/helper.rb +12 -3
  74. data/lib/pry/version.rb +1 -1
  75. data/lib/pry/wrapped_module.rb +7 -7
  76. data/lib/pry/{module_candidate.rb → wrapped_module/candidate.rb} +7 -13
  77. metadata +14 -19
@@ -46,7 +46,7 @@ class Pry
46
46
  # code defined in pry, eval'd within pry.
47
47
  repl_edit
48
48
  elsif runtime_patch?
49
- # patch code without persisting changes
49
+ # patch code without persisting changes, implies future changes are patches
50
50
  apply_runtime_patch
51
51
  else
52
52
  # code stored in actual files, eval'd at top-level
@@ -72,7 +72,7 @@ class Pry
72
72
  end
73
73
 
74
74
  def runtime_patch?
75
- !file_based_exception? && (opts.present?(:patch) || pry_method?(code_object))
75
+ !file_based_exception? && (opts.present?(:patch) || previously_patched?(code_object) || pry_method?(code_object))
76
76
  end
77
77
 
78
78
  def apply_runtime_patch
@@ -140,6 +140,10 @@ class Pry
140
140
  code_object.pry_method?
141
141
  end
142
142
 
143
+ def previously_patched?(code_object)
144
+ code_object.is_a?(Pry::Method) && Pry::Method::Patcher.code_for(code_object.source_location.first)
145
+ end
146
+
143
147
  def patch_exception?
144
148
  opts.present?(:ex) && opts.present?(:patch)
145
149
  end
@@ -153,7 +157,7 @@ class Pry
153
157
  case opts[:i]
154
158
  when Range
155
159
  (_pry_.input_array[opts[:i]] || []).join
156
- when Fixnum
160
+ when Integer
157
161
  _pry_.input_array[opts[:i]] || ""
158
162
  else
159
163
  raise Pry::CommandError, "Not a valid range: #{opts[:i]}"
@@ -7,7 +7,7 @@ class Pry
7
7
  end
8
8
 
9
9
  def from_code_object(code_object, filename_argument)
10
- if File.exists?(code_object.source_file.to_s)
10
+ if File.exist?(code_object.source_file.to_s)
11
11
  [code_object.source_file, code_object.source_line]
12
12
  else
13
13
  raise CommandError, "Cannot find a file for #{filename_argument}!"
@@ -20,7 +20,7 @@ class Pry
20
20
  find-method re Pry
21
21
 
22
22
  # Find all methods that contain the code:
23
- # output.puts inside the Pry namepsace.
23
+ # output.puts inside the Pry namespace.
24
24
  find-method -c 'output.puts' Pry
25
25
  BANNER
26
26
 
@@ -16,7 +16,7 @@ class Pry
16
16
 
17
17
  def process(gem)
18
18
  Dir.chdir(Rubygem.spec(gem).full_gem_path) do
19
- Pry::Editor.invoke_editor(".", 0, false)
19
+ Pry::Editor.new(_pry_).invoke_editor(".", 0, false)
20
20
  end
21
21
  end
22
22
 
@@ -0,0 +1,25 @@
1
+ class Pry::Command::GemReadme < Pry::ClassCommand
2
+ match 'gem-readme'
3
+ description 'Show the readme bundled with a rubygem'
4
+ group 'Gems'
5
+ command_options argument_required: true
6
+ banner <<-BANNER
7
+ gem-readme gem
8
+ Show the readme bundled with a rubygem
9
+ BANNER
10
+
11
+ def process(name)
12
+ spec = Gem::Specification.find_by_name(name)
13
+ glob = File.join(spec.full_gem_path, 'README*')
14
+ readme = Dir[glob][0]
15
+ if File.exist?(readme.to_s)
16
+ _pry_.pager.page File.read(readme)
17
+ else
18
+ raise Pry::CommandError, "Gem '#{name}' doesn't appear to have a README"
19
+ end
20
+ rescue Gem::LoadError
21
+ raise Pry::CommandError, "Gem '#{name}' wasn't found. Are you sure it is installed?"
22
+ end
23
+
24
+ Pry::Commands.add_command(self)
25
+ end
@@ -0,0 +1,40 @@
1
+ class Pry::Command::GemSearch < Pry::ClassCommand
2
+ match 'gem-search'
3
+ description 'Search for a gem with the rubygems.org JSON API'
4
+ group 'Gems'
5
+ command_options argument_required: true
6
+ banner <<-BANNER
7
+ gem-search [options] gem
8
+ Search for a gem with the rubygems.org HTTP API
9
+ BANNER
10
+
11
+ API_ENDPOINT = 'https://rubygems.org/api/v1/search.json'
12
+
13
+ def setup
14
+ require 'json' unless defined?(JSON)
15
+ require 'net/http' unless defined?(Net::HTTP)
16
+ end
17
+
18
+ def options(opt)
19
+ opt.on :l, :limit, 'Limit the number of results (max: 30)',
20
+ default: 10,
21
+ as: Integer,
22
+ argument: true
23
+ end
24
+
25
+ def process(str)
26
+ uri = URI.parse(API_ENDPOINT)
27
+ uri.query = URI.encode_www_form(query: str)
28
+ gems = JSON.load Net::HTTP.get(uri)
29
+ _pry_.pager.page list_as_string(gems, opts[:limit])
30
+ end
31
+
32
+ private
33
+ def list_as_string(gems, limit = 10)
34
+ gems[0..limit-1].map do |gem|
35
+ name, version, info = gem.values_at 'name', 'version', 'info'
36
+ "#{text.bold(name)} #{text.bold('v'+version)} \n#{info}\n\n"
37
+ end.join
38
+ end
39
+ Pry::Commands.add_command(self)
40
+ end
@@ -170,8 +170,8 @@ class Pry
170
170
  else
171
171
  Pry.history.to_a.last(Pry.history.session_line_count)
172
172
  end
173
- # The last value in history will be the 'hist' command itself.
174
- Pry::Code(h[0..-2])
173
+
174
+ Pry::Code(Pry.history.filter(h[0..-2]))
175
175
  end
176
176
  end
177
177
 
@@ -9,18 +9,18 @@ class Pry
9
9
  BANNER
10
10
 
11
11
  def process(break_level)
12
- break_level = break_level.to_i
13
- nesting_level = _pry_.binding_stack.size - 1
12
+ break_level = break_level.to_i
13
+ nesting_level = _pry_.binding_stack.size - 1
14
+ max_nest_level = nesting_level - 1
14
15
 
15
16
  case break_level
16
17
  when nesting_level
17
18
  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
-
19
+ when 0..max_nest_level
20
+ _pry_.binding_stack = _pry_.binding_stack[0..break_level]
21
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}."
22
+ output.puts "Invalid nest level. Must be between 0 and " \
23
+ "#{max_nest_level}. Got #{break_level}."
24
24
  end
25
25
  end
26
26
  end
@@ -61,7 +61,9 @@ class Pry
61
61
  " " * 32 << "Constants that are pending autoload? are also shown (in yellow)"
62
62
  opt.on :i, :ivars, "Show instance variables (in blue) and class variables (in bright blue)"
63
63
  opt.on :G, :grep, "Filter output by regular expression", :argument => true
64
-
64
+ if Object.respond_to?(:deprecate_constant)
65
+ opt.on :d, :dconstants, "Show deprecated constants"
66
+ end
65
67
  if jruby?
66
68
  opt.on :J, "all-java", "Show all the aliases for methods from java (default is to show only prettiest)"
67
69
  end
@@ -3,15 +3,17 @@ require 'pry/commands/ls/interrogatable'
3
3
  class Pry
4
4
  class Command::Ls < Pry::ClassCommand
5
5
  class Constants < Pry::Command::Ls::Formatter
6
+ DEPRECATED_CONSTANTS = [:Fixnum, :Bignum, :TimeoutError, :NIL, :FALSE, :TRUE]
7
+ DEPRECATED_CONSTANTS << :JavaPackageModuleTemplate if Pry::Helpers::BaseHelpers.jruby?
6
8
  include Pry::Command::Ls::Interrogatable
7
9
 
8
-
9
10
  def initialize(interrogatee, no_user_opts, opts, _pry_)
10
11
  super(_pry_)
11
12
  @interrogatee = interrogatee
12
13
  @no_user_opts = no_user_opts
13
14
  @default_switch = opts[:constants]
14
15
  @verbose_switch = opts[:verbose]
16
+ @dconstants = opts.dconstants?
15
17
  end
16
18
 
17
19
  def correct_opts?
@@ -26,8 +28,17 @@ class Pry
26
28
 
27
29
  private
28
30
 
31
+ def show_deprecated_constants?
32
+ @dconstants == true
33
+ end
34
+
29
35
  def format(mod, constants)
30
36
  constants.sort_by(&:downcase).map do |name|
37
+ if Object.respond_to?(:deprecate_constant) and
38
+ DEPRECATED_CONSTANTS.include?(name) and
39
+ !show_deprecated_constants?
40
+ next
41
+ end
31
42
  if const = (!mod.autoload?(name) && (mod.const_get(name) || true) rescue nil)
32
43
  if (const < Exception rescue false)
33
44
  color(:exception_constant, name)
@@ -7,6 +7,7 @@ class Pry
7
7
  def initialize(_pry_)
8
8
  @_pry_ = _pry_
9
9
  @target = _pry_.current_context
10
+ @default_switch = nil
10
11
  end
11
12
 
12
13
  def write_out
@@ -19,7 +19,7 @@ module Pry::Command::Ls::JRubyHacks
19
19
  m.name.sub(/\A(is|get|set)(?=[A-Z_])/, '').gsub(/[_?=]/, '').downcase
20
20
  end
21
21
 
22
- grouped.map do |key, values|
22
+ grouped.flat_map do |key, values|
23
23
  values = values.sort_by do |m|
24
24
  rubbishness(m.name)
25
25
  end
@@ -28,7 +28,7 @@ module Pry::Command::Ls::JRubyHacks
28
28
  values.select do |x|
29
29
  (!found.any? { |y| x == y }) && found << x
30
30
  end
31
- end.flatten(1)
31
+ end
32
32
  end
33
33
 
34
34
  # When removing jruby aliases, we want to keep the alias that is
@@ -11,6 +11,8 @@ class Pry
11
11
  super(_pry_)
12
12
  @interrogatee = interrogatee
13
13
  @no_user_opts = no_user_opts
14
+ @ppp_switch = opts[:ppp]
15
+ @jruby_switch = opts['all-java']
14
16
  end
15
17
 
16
18
  def output_self
@@ -12,7 +12,7 @@ class Pry
12
12
 
13
13
  play --lines 149..153 # assumes current context
14
14
  play -i 20 --lines 1..3 # assumes lines of the input expression at 20
15
- play -o 4 # the output of of an expression at 4
15
+ play -o 4 # the output of an expression at 4
16
16
  play Pry#repl -l 1..-1 # play the contents of Pry#repl method
17
17
  play -e 2 # play from specified line until end of valid expression
18
18
  play hello.rb # play a file
@@ -91,7 +91,7 @@ class Pry
91
91
  end
92
92
 
93
93
  def file_content
94
- if default_file && File.exists?(default_file)
94
+ if default_file && File.exist?(default_file)
95
95
  @cc.restrict_to_lines(File.read(default_file), @cc.line_range)
96
96
  else
97
97
  raise CommandError, "File does not exist! File was: #{default_file.inspect}"
@@ -31,7 +31,7 @@ class Pry
31
31
  end
32
32
 
33
33
  def reload_current_file
34
- if !File.exists?(current_file)
34
+ if !File.exist?(current_file)
35
35
  raise CommandError, "Current file: #{current_file} cannot be found on disk!"
36
36
  end
37
37
 
@@ -49,7 +49,7 @@ class Pry
49
49
  def check_for_reloadability(code_object, identifier)
50
50
  if !code_object || !code_object.source_file
51
51
  raise CommandError, "Cannot locate #{identifier}!"
52
- elsif !File.exists?(code_object.source_file)
52
+ elsif !File.exist?(code_object.source_file)
53
53
  raise CommandError,
54
54
  "Cannot reload #{identifier} as it has no associated file on disk. " \
55
55
  "File found was: #{code_object.source_file}"
@@ -14,6 +14,10 @@ class Pry
14
14
  BANNER
15
15
 
16
16
  def process(spec)
17
+ unless spec
18
+ return output.puts "Please provide a class, module, or method name (e.g: ri Array#push)"
19
+ end
20
+
17
21
  # Lazily load RI
18
22
  require 'rdoc/ri/driver'
19
23
 
@@ -4,7 +4,7 @@ class Pry
4
4
  group 'Input and Output'
5
5
  description "All text following a '.' is forwarded to the shell."
6
6
  command_options :listing => '.<shell command>', :use_prefix => false,
7
- :takes_block => true
7
+ :takes_block => true
8
8
 
9
9
  banner <<-'BANNER'
10
10
  Usage: .COMMAND_NAME
@@ -30,18 +30,44 @@ class Pry
30
30
 
31
31
  private
32
32
 
33
- def parse_destination(dest)
34
- return "~" if dest.empty?
35
- return dest unless dest == "-"
36
- state.old_pwd || raise(CommandError, "No prior directory available")
37
- end
33
+ def parse_destination(dest)
34
+ return "~" if dest.empty?
35
+ return dest unless dest == "-"
36
+ state.old_pwd || raise(CommandError, "No prior directory available")
37
+ end
38
38
 
39
- def process_cd(dest)
39
+ def process_cd(dest)
40
+ begin
40
41
  state.old_pwd = Dir.pwd
41
- Dir.chdir File.expand_path(dest)
42
+ Dir.chdir(File.expand_path(path_from_cd_path(dest) || dest))
42
43
  rescue Errno::ENOENT
43
44
  raise CommandError, "No such directory: #{dest}"
44
45
  end
46
+ end
47
+
48
+ def cd_path_env
49
+ ENV['CDPATH']
50
+ end
51
+
52
+ def cd_path_exists?
53
+ cd_path_env && cd_path_env.length.nonzero?
54
+ end
55
+
56
+ def path_from_cd_path(dest)
57
+ return if !(dest && cd_path_exists?) || special_case_path?(dest)
58
+
59
+ cd_path_env.split(File::PATH_SEPARATOR).each do |path|
60
+ if File.directory?(path) && path.split(File::SEPARATOR).last == dest
61
+ return path
62
+ end
63
+ end
64
+
65
+ return nil
66
+ end
67
+
68
+ def special_case_path?(dest)
69
+ ['.', '..', '-'].include?(dest) || dest =~ /\A[#{File::PATH_SEPARATOR}~]/
70
+ end
45
71
  end
46
72
 
47
73
  Pry::Commands.add_command(Pry::Command::ShellCommand)
@@ -22,7 +22,15 @@ class Pry
22
22
  raise CommandError, no_definition_message if !code_object
23
23
  @original_code_object = code_object
24
24
 
25
- if show_all_modules?(code_object)
25
+ if !obj_name && code_object.c_module? && !opts[:all]
26
+ result = "Warning: You're inside an object, whose class is defined by means\n" +
27
+ " of the C Ruby API. Pry cannot display the information for\n" +
28
+ " this class."
29
+ if code_object.candidates.any?
30
+ result += "\n However, you can view monkey-patches applied to this class.\n" +
31
+ " Just execute the same command with the '--all' switch."
32
+ end
33
+ elsif show_all_modules?(code_object)
26
34
  # show all monkey patches for a module
27
35
 
28
36
  result = content_and_headers_for_all_module_candidates(code_object)
@@ -85,7 +93,7 @@ class Pry
85
93
  end
86
94
 
87
95
  def no_definition_message
88
- "Couldn't locate a definition for #{obj_name}!"
96
+ "Couldn't locate a definition for #{obj_name}"
89
97
  end
90
98
 
91
99
  # Generate a header (meta-data information) for all the code
@@ -10,7 +10,7 @@ class Pry
10
10
  end
11
11
 
12
12
  def eval!
13
- @previous_value = @value
13
+ @previous_value = value
14
14
  @value = Pry::ColorPrinter.pp(target_eval(target, source), "")
15
15
  end
16
16
 
@@ -159,12 +159,12 @@ class Pry
159
159
  end
160
160
 
161
161
  def class_code
162
- return @class_code if @class_code
163
-
164
- mod = @method ? Pry::WrappedModule(@method.owner) : target_class
165
-
166
- idx = mod.candidates.find_index { |v| expand_path(v.source_file) == @file }
167
- @class_code = idx && Pry::Code.from_module(mod, idx)
162
+ @class_code ||=
163
+ begin
164
+ mod = @method ? Pry::WrappedModule(@method.owner) : target_class
165
+ idx = mod.candidates.find_index { |v| expand_path(v.source_file) == @file }
166
+ idx && Pry::Code.from_module(mod, idx)
167
+ end
168
168
  end
169
169
 
170
170
  def valid_method?
@@ -193,4 +193,5 @@ class Pry
193
193
 
194
194
  Pry::Commands.add_command(Pry::Command::Whereami)
195
195
  Pry::Commands.alias_command '@', 'whereami'
196
+ Pry::Commands.alias_command /whereami[!?]+/, 'whereami'
196
197
  end
data/lib/pry/config.rb CHANGED
@@ -1,24 +1,11 @@
1
- class Pry::Config
1
+ require_relative 'basic_object'
2
+ class Pry::Config < Pry::BasicObject
2
3
  require_relative 'config/behavior'
4
+ require_relative 'config/memoization'
3
5
  require_relative 'config/default'
4
6
  require_relative 'config/convenience'
5
7
  include Pry::Config::Behavior
6
-
7
8
  def self.shortcuts
8
9
  Convenience::SHORTCUTS
9
10
  end
10
-
11
- #
12
- # FIXME
13
- # @param [Pry::Hooks] hooks
14
- #
15
- def hooks=(hooks)
16
- if hooks.is_a?(Hash)
17
- warn "Hash-based hooks are now deprecated! Use a `Pry::Hooks` object " \
18
- "instead! http://rubydoc.info/github/pry/pry/master/Pry/Hooks"
19
- self["hooks"] = Pry::Hooks.from_hash(hooks)
20
- else
21
- self["hooks"] = hooks
22
- end
23
- end
24
11
  end