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
@@ -0,0 +1,14 @@
1
+ module Pry::Testable::Mockable
2
+ def mock_command(cmd, args = [], opts = {})
3
+ output = StringIO.new
4
+ pry = Pry.new(output: output)
5
+ ret = cmd.new(opts.merge(pry_instance: pry, output: output)).call_safely(*args)
6
+ Struct.new(:output, :return).new(output.string, ret)
7
+ end
8
+
9
+ def mock_exception(*mock_backtrace)
10
+ StandardError.new.tap do |e|
11
+ e.define_singleton_method(:backtrace) { mock_backtrace }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,73 @@
1
+ class Pry::Testable::PryTester
2
+ extend Pry::Forwardable
3
+ attr_reader :pry, :out
4
+ def_delegators :@pry, :eval_string, :eval_string=
5
+
6
+ def initialize(target = TOPLEVEL_BINDING, options = {})
7
+ @pry = Pry.new(options.merge(target: target))
8
+ @history = options[:history]
9
+ @pry.inject_sticky_locals!
10
+ reset_output
11
+ end
12
+
13
+ def eval(*strs)
14
+ reset_output
15
+ result = nil
16
+
17
+ strs.flatten.each do |str|
18
+ # Check for space prefix. See #1369.
19
+ if str !~ /^\s\S/
20
+ str = "#{str.strip}\n"
21
+ end
22
+ @history.push str if @history
23
+
24
+ if @pry.process_command(str)
25
+ result = last_command_result_or_output
26
+ else
27
+ result = @pry.evaluate_ruby(str)
28
+ end
29
+ end
30
+
31
+ result
32
+ end
33
+
34
+ def push(*lines)
35
+ Array(lines).flatten.each do |line|
36
+ @pry.eval(line)
37
+ end
38
+ end
39
+
40
+ def push_binding(context)
41
+ @pry.push_binding context
42
+ end
43
+
44
+ def last_output
45
+ @out.string if @out
46
+ end
47
+
48
+ def process_command(command_str)
49
+ @pry.process_command(command_str) or raise "Not a valid command"
50
+ last_command_result_or_output
51
+ end
52
+
53
+ def last_command_result
54
+ result = Pry.current[:pry_cmd_result]
55
+ result.retval if result
56
+ end
57
+
58
+ protected
59
+
60
+ def last_command_result_or_output
61
+ result = last_command_result
62
+ if result != Pry::Command::VOID_VALUE
63
+ result
64
+ else
65
+ last_output
66
+ end
67
+ end
68
+
69
+ def reset_output
70
+ @out = StringIO.new
71
+ @pry.output = @out
72
+ end
73
+ end
@@ -0,0 +1,26 @@
1
+ module Pry::Testable::Utility
2
+ #
3
+ # Creates a Tempfile then unlinks it after the block has yielded.
4
+ #
5
+ # @yieldparam [String] file
6
+ # The path of the temp file
7
+ #
8
+ # @return [void]
9
+ #
10
+ def temp_file(ext = '.rb')
11
+ file = Tempfile.open(['pry', ext])
12
+ yield file
13
+ ensure
14
+ file.close(true) if file
15
+ end
16
+
17
+ def unindent(*args)
18
+ Pry::Helpers::CommandHelpers.unindent(*args)
19
+ end
20
+
21
+ def inner_scope
22
+ catch(:inner_scope) do
23
+ yield -> { throw(:inner_scope, self) }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,46 @@
1
+ module Pry::Testable::Variables
2
+ #
3
+ # @example
4
+ # temporary_constants(:Foo, :Bar) do
5
+ # Foo = Class.new(RuntimeError)
6
+ # Bar = Class.new(RuntimeError)
7
+ # end
8
+ # Foo # => NameError
9
+ # Bar # => NameError
10
+ #
11
+ # @param [Array<Symbol>] names
12
+ # An array of constant names that be defined by a block,
13
+ # and removed by this method afterwards.
14
+ #
15
+ # @return [void]
16
+ #
17
+ def temporary_constants(*names)
18
+ names.each do |name|
19
+ Object.remove_const name if Object.const_defined?(name)
20
+ end
21
+ yield
22
+ ensure
23
+ names.each do |name|
24
+ Object.remove_const name if Object.const_defined?(name)
25
+ end
26
+ end
27
+
28
+ #
29
+ # @param [String] name
30
+ # The name of a variable.
31
+ #
32
+ # @param [String] value
33
+ # Its value.
34
+ #
35
+ # @param [Binding] b
36
+ # The binding object to insert a variable into.
37
+ #
38
+ # @return [void]
39
+ #
40
+ def insert_variable(name, value, b)
41
+ Pry.current[:pry_local] = value
42
+ b.eval("#{name} = ::Pry.current[:pry_local]")
43
+ ensure
44
+ Pry.current[:pry_local] = nil
45
+ end
46
+ end
@@ -0,0 +1,70 @@
1
+ # good idea ???
2
+ # if you're testing pry plugin you should require pry by yourself, no?
3
+ require 'pry' if not defined?(Pry)
4
+
5
+ module Pry::Testable
6
+ extend self
7
+ require_relative "testable/pry_tester"
8
+ require_relative "testable/evalable"
9
+ require_relative "testable/mockable"
10
+ require_relative "testable/variables"
11
+ require_relative "testable/utility"
12
+
13
+ #
14
+ # When {Pry::Testable} is included into another module or class,
15
+ # the following modules are also included: {Pry::Testable::Mockable},
16
+ # {Pry::Testable::Evalable}, {Pry::Testable::Variables}, and
17
+ # {Pry::Testable::Utility}.
18
+ #
19
+ # @note
20
+ # Each of the included modules mentioned above may also be used
21
+ # standalone or in a pick-and-mix fashion.
22
+ #
23
+ # @param [Module] mod
24
+ # A class or module.
25
+ #
26
+ # @return [void]
27
+ #
28
+ def self.included(mod)
29
+ mod.module_eval do
30
+ include Pry::Testable::Mockable
31
+ include Pry::Testable::Evalable
32
+ include Pry::Testable::Variables
33
+ include Pry::Testable::Utility
34
+ end
35
+ end
36
+
37
+ TEST_DEFAULTS = {
38
+ color: false,
39
+ pager: false,
40
+ should_load_rc: false,
41
+ should_load_local_rc: false,
42
+ correct_indent: false,
43
+ collison_warning: false,
44
+ history: {
45
+ should_load: false,
46
+ should_save: false
47
+ }
48
+ }
49
+ private_constant :TEST_DEFAULTS
50
+
51
+ #
52
+ # Sets various configuration options that make Pry optimal for a test
53
+ # environment, see source code for complete details.
54
+ #
55
+ # @return [void]
56
+ #
57
+ def self.set_testenv_variables
58
+ Pry.config = Pry::Config.from_hash(TEST_DEFAULTS, Pry::Config::Default.new)
59
+ Pry.config.hooks = Pry::Hooks.new
60
+ end
61
+
62
+ #
63
+ # Reset the Pry configuration to their default values.
64
+ #
65
+ # @return [void]
66
+ #
67
+ def self.unset_testenv_variables
68
+ Pry.config = Pry::Config.from_hash({}, Pry::Config::Default.new)
69
+ end
70
+ end
data/lib/pry/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Pry
2
- VERSION = "0.10.3"
2
+ VERSION = '0.12.2'.freeze
3
3
  end
@@ -1,16 +1,14 @@
1
1
  require 'pry/helpers/documentation_helpers'
2
- require 'forwardable'
3
2
 
4
3
  class Pry
5
4
  class WrappedModule
6
-
7
5
  # This class represents a single candidate for a module/class definition.
8
6
  # It provides access to the source, documentation, line and file
9
7
  # for a monkeypatch (reopening) of a class/module.
10
8
  class Candidate
11
9
  include Pry::Helpers::DocumentationHelpers
12
10
  include Pry::CodeObject::Helpers
13
- extend Forwardable
11
+ extend Pry::Forwardable
14
12
 
15
13
  # @return [String] The file where the module definition is located.
16
14
  attr_reader :file
@@ -22,15 +20,12 @@ class Pry
22
20
 
23
21
  # Methods to delegate to associated `Pry::WrappedModule
24
22
  # instance`.
25
- private_delegates = [:lines_for_file, :method_candidates,
26
- :yard_docs?]
27
-
28
- public_delegates = [:wrapped, :module?, :class?, :name, :nonblank_name,
23
+ private_delegates = [:lines_for_file, :method_candidates, :yard_docs?, :name]
24
+ public_delegates = [:wrapped, :module?, :class?, :nonblank_name,
29
25
  :number_of_candidates]
30
26
 
31
- def_delegators :@wrapper, *(private_delegates + public_delegates)
32
- private(*private_delegates)
33
- public(*public_delegates)
27
+ def_delegators :@wrapper, *public_delegates
28
+ def_private_delegators :@wrapper, *private_delegates
34
29
 
35
30
  # @raise [Pry::CommandError] If `rank` is out of bounds.
36
31
  # @param [Pry::WrappedModule] wrapper The associated
@@ -49,6 +44,7 @@ class Pry
49
44
  raise CommandError, "No such module candidate. Allowed candidates range is from 0 to #{number_of_candidates - 1}"
50
45
  end
51
46
 
47
+ @source = @source_location = nil
52
48
  @rank = rank
53
49
  @file, @line = source_location
54
50
  end
@@ -60,16 +56,15 @@ class Pry
60
56
  return nil if file.nil?
61
57
  return @source if @source
62
58
 
63
- @source = strip_leading_whitespace(Pry::Code.from_file(file).expression_at(line, number_of_lines_in_first_chunk))
59
+ @source ||= strip_leading_whitespace(Pry::Code.from_file(file).expression_at(line, number_of_lines_in_first_chunk))
64
60
  end
65
61
 
66
62
  # @raise [Pry::CommandError] If documentation cannot be found.
67
63
  # @return [String] The documentation for the candidate.
68
64
  def doc
69
65
  return nil if file.nil?
70
- return @doc if @doc
71
66
 
72
- @doc = get_comment_content(Pry::Code.from_file(file).comment_describing(line))
67
+ @doc ||= get_comment_content(Pry::Code.from_file(file).comment_describing(line))
73
68
  end
74
69
 
75
70
  # @return [Array, nil] A `[String, Fixnum]` pair representing the
@@ -81,7 +76,7 @@ class Pry
81
76
  file, line = first_method_source_location
82
77
  return nil if !file.is_a?(String)
83
78
 
84
- @source_location = [file, first_line_of_module_definition(file, line)]
79
+ @source_location = [file, first_line_of_module_definition(file, line)]
85
80
  rescue Pry::RescuableException
86
81
  nil
87
82
  end
@@ -1,4 +1,4 @@
1
- require 'pry/module_candidate'
1
+ require 'pry/wrapped_module/candidate'
2
2
 
3
3
  class Pry
4
4
  class << self
@@ -26,7 +26,7 @@ class Pry
26
26
  # @return [Module, nil] The module or `nil` (if conversion failed).
27
27
  # @example
28
28
  # Pry::WrappedModule.from_str("Pry::Code")
29
- def self.from_str(mod_name, target=TOPLEVEL_BINDING)
29
+ def self.from_str(mod_name, target = TOPLEVEL_BINDING)
30
30
  if safe_to_evaluate?(mod_name, target)
31
31
  Pry::WrappedModule.new(target.eval(mod_name))
32
32
  else
@@ -48,6 +48,8 @@ class Pry
48
48
  # @return [Boolean]
49
49
  def safe_to_evaluate?(str, target)
50
50
  return true if str.strip == "self"
51
+ return false if str =~ /%/
52
+
51
53
  kind = target.eval("defined?(#{str})")
52
54
  kind =~ /variable|constant/
53
55
  end
@@ -57,12 +59,14 @@ class Pry
57
59
  # @param [Module] mod
58
60
  def initialize(mod)
59
61
  raise ArgumentError, "Tried to initialize a WrappedModule with a non-module #{mod.inspect}" unless ::Module === mod
62
+
60
63
  @wrapped = mod
61
64
  @memoized_candidates = []
62
65
  @host_file_lines = nil
63
66
  @source = nil
64
67
  @source_location = nil
65
68
  @doc = nil
69
+ @all_source_locations_by_popularity = nil
66
70
  end
67
71
 
68
72
  # Returns an array of the names of the constants accessible in the wrapped
@@ -107,10 +111,6 @@ class Pry
107
111
  def singleton_class?
108
112
  if Pry::Method.safe_send(wrapped, :respond_to?, :singleton_class?)
109
113
  Pry::Method.safe_send(wrapped, :singleton_class?)
110
- elsif defined?(Rubinius)
111
- # https://github.com/rubinius/rubinius/commit/2e71722dba53d1a92c54d5e3968d64d1042486fe singleton_class? added 30 Jul 2014
112
- # https://github.com/rubinius/rubinius/commit/4310f6b2ef3c8fc88135affe697db4e29e4621c4 has been around since 2011
113
- !!Rubinius::Type.singleton_class_object(wrapped)
114
114
  else
115
115
  wrapped != Pry::Method.safe_send(wrapped, :ancestors).first
116
116
  end
@@ -136,10 +136,10 @@ class Pry
136
136
  def singleton_instance
137
137
  raise ArgumentError, "tried to get instance of non singleton class" unless singleton_class?
138
138
 
139
- if Helpers::BaseHelpers.jruby?
139
+ if Helpers::Platform.jruby?
140
140
  wrapped.to_java.attached
141
141
  else
142
- @singleton_instance ||= ObjectSpace.each_object(wrapped).detect{ |x| (class << x; self; end) == wrapped }
142
+ @singleton_instance ||= ObjectSpace.each_object(wrapped).detect { |x| (class << x; self; end) == wrapped }
143
143
  end
144
144
  end
145
145
 
@@ -148,15 +148,14 @@ class Pry
148
148
  wrapped.send(method_name, *args, &block)
149
149
  end
150
150
 
151
- def respond_to?(method_name)
152
- super || wrapped.respond_to?(method_name)
151
+ def respond_to?(method_name, include_all = false)
152
+ super || wrapped.respond_to?(method_name, include_all)
153
153
  end
154
154
 
155
155
  # Retrieve the source location of a module. Return value is in same
156
156
  # format as Method#source_location. If the source location
157
157
  # cannot be found this method returns `nil`.
158
158
  #
159
- # @param [Module] mod The module (or class).
160
159
  # @return [Array<String, Fixnum>, nil] The source location of the
161
160
  # module (or class), or `nil` if no source location found.
162
161
  def source_location
@@ -231,7 +230,7 @@ class Pry
231
230
  # @param [Fixnum] rank
232
231
  # @return [Pry::WrappedModule::Candidate]
233
232
  def candidate(rank)
234
- @memoized_candidates[rank] ||= Candidate.new(self, rank)
233
+ @memoized_candidates[rank] ||= WrappedModule::Candidate.new(self, rank)
235
234
  end
236
235
 
237
236
  # @return [Fixnum] The number of candidate definitions for the
@@ -252,7 +251,7 @@ class Pry
252
251
  y.yield candidate(num)
253
252
  end
254
253
  end
255
- Pry::Helpers::BaseHelpers.jruby_19? ? enum.to_a : enum
254
+ Helpers::Platform.jruby_19? ? enum.to_a : enum
256
255
  end
257
256
 
258
257
  # @return [Boolean] Whether YARD docs are available for this module.
@@ -266,7 +265,7 @@ class Pry
266
265
  # When `self` is a `Module` then return the
267
266
  # nth ancestor, otherwise (in the case of classes) return the
268
267
  # nth ancestor that is a class.
269
- def super(times=1)
268
+ def super(times = 1)
270
269
  return self if times.zero?
271
270
 
272
271
  if wrapped.is_a?(Class)
@@ -301,7 +300,7 @@ class Pry
301
300
  # speed up source code extraction.
302
301
  def method_candidates
303
302
  @method_candidates ||= all_source_locations_by_popularity.map do |group|
304
- methods_sorted_by_source_line = group.last.sort_by(&:source_line)
303
+ methods_sorted_by_source_line = group.last.sort_by(&:source_line)
305
304
  [methods_sorted_by_source_line.first, methods_sorted_by_source_line.last]
306
305
  end
307
306
  end
@@ -314,7 +313,7 @@ class Pry
314
313
  @all_source_locations_by_popularity = ims.group_by { |v| Array(v.source_location).first }.
315
314
  sort_by do |path, methods|
316
315
  expanded = File.expand_path(path)
317
- load_order = $LOADED_FEATURES.index{ |file| expanded.end_with?(file) }
316
+ load_order = $LOADED_FEATURES.index { |file| expanded.end_with?(file) }
318
317
 
319
318
  [-methods.size, load_order || (1.0 / 0.0)]
320
319
  end
@@ -322,21 +321,21 @@ class Pry
322
321
 
323
322
  # We only want methods that have a non-nil `source_location`. We also
324
323
  # skip some spooky internal methods.
325
- # (i.e we skip `__class_init__` because it's an odd rbx specific thing that causes tests to fail.)
324
+ #
326
325
  # @return [Array<Pry::Method>]
327
326
  def all_relevant_methods_for(mod)
328
327
  methods = all_methods_for(mod).select(&:source_location).
329
- reject{ |x| x.name == '__class_init__' || method_defined_by_forwardable_module?(x) }
328
+ reject { |x| method_defined_by_forwardable_module?(x) }
330
329
 
331
330
  return methods unless methods.empty?
332
331
 
333
- safe_send(mod, :constants).map do |const_name|
334
- if const = nested_module?(mod, const_name)
332
+ safe_send(mod, :constants).flat_map do |const_name|
333
+ if (const = nested_module?(mod, const_name))
335
334
  all_relevant_methods_for(const)
336
335
  else
337
336
  []
338
337
  end
339
- end.flatten
338
+ end
340
339
  end
341
340
 
342
341
  # Return all methods (instance methods and class methods) for a
@@ -348,9 +347,11 @@ class Pry
348
347
 
349
348
  def nested_module?(parent, name)
350
349
  return if safe_send(parent, :autoload?, name)
350
+
351
351
  child = safe_send(parent, :const_get, name)
352
352
  return unless Module === child
353
353
  return unless safe_send(child, :name) == "#{safe_send(parent, :name)}::#{name}"
354
+
354
355
  child
355
356
  end
356
357
 
data/lib/pry.rb CHANGED
@@ -1,18 +1,16 @@
1
- # (C) John Mair (banisterfiend) 2013
2
- # MIT License
3
- #
4
1
  require 'pp'
5
-
2
+ require 'pry/forwardable'
6
3
  require 'pry/input_lock'
7
4
  require 'pry/exceptions'
5
+ require 'pry/platform'
8
6
  require 'pry/helpers/base_helpers'
9
7
  require 'pry/hooks'
10
- require 'forwardable'
11
8
 
12
9
  class Pry
13
10
  # The default hooks - display messages when beginning and ending Pry sessions.
14
11
  DEFAULT_HOOKS = Pry::Hooks.new.add_hook(:before_session, :default) do |out, target, _pry_|
15
12
  next if _pry_.quiet?
13
+
16
14
  _pry_.run_command("whereami --quiet")
17
15
  end
18
16
 
@@ -46,47 +44,18 @@ class Pry
46
44
  else
47
45
  output.puts "#{exception.class}: #{exception.message}"
48
46
  output.puts "from #{exception.backtrace.first}"
47
+
48
+ if exception.respond_to? :cause
49
+ cause = exception.cause
50
+ while cause
51
+ output.puts "Caused by #{cause.class}: #{cause}\n"
52
+ output.puts "from #{cause.backtrace.first}"
53
+ cause = cause.cause
54
+ end
55
+ end
49
56
  end
50
57
  end
51
58
 
52
- DEFAULT_PROMPT_NAME = 'pry'
53
-
54
- # The default prompt; includes the target and nesting level
55
- DEFAULT_PROMPT = [
56
- proc { |target_self, nest_level, pry|
57
- "[#{pry.input_array.size}] #{pry.config.prompt_name}(#{Pry.view_clip(target_self)})#{":#{nest_level}" unless nest_level.zero?}> "
58
- },
59
-
60
- proc { |target_self, nest_level, pry|
61
- "[#{pry.input_array.size}] #{pry.config.prompt_name}(#{Pry.view_clip(target_self)})#{":#{nest_level}" unless nest_level.zero?}* "
62
- }
63
- ]
64
-
65
- DEFAULT_PROMPT_SAFE_OBJECTS = [String, Numeric, Symbol, nil, true, false]
66
-
67
- # A simple prompt - doesn't display target or nesting level
68
- SIMPLE_PROMPT = [proc { ">> " }, proc { " | " }]
69
-
70
- NO_PROMPT = [proc { '' }, proc { '' }]
71
-
72
- SHELL_PROMPT = [
73
- proc { |target_self, _, _pry_| "#{_pry_.config.prompt_name} #{Pry.view_clip(target_self)}:#{Dir.pwd} $ " },
74
- proc { |target_self, _, _pry_| "#{_pry_.config.prompt_name} #{Pry.view_clip(target_self)}:#{Dir.pwd} * " }
75
- ]
76
-
77
- # A prompt that includes the full object path as well as
78
- # input/output (_in_ and _out_) information. Good for navigation.
79
- NAV_PROMPT = [
80
- proc do |_, _, _pry_|
81
- tree = _pry_.binding_stack.map { |b| Pry.view_clip(b.eval("self")) }.join " / "
82
- "[#{_pry_.input_array.count}] (#{_pry_.config.prompt_name}) #{tree}: #{_pry_.binding_stack.size - 1}> "
83
- end,
84
- proc do |_, _, _pry_|
85
- tree = _pry_.binding_stack.map { |b| Pry.view_clip(b.eval("self")) }.join " / "
86
- "[#{_pry_.input_array.count}] (#{ _pry_.config.prompt_name}) #{tree}: #{_pry_.binding_stack.size - 1}* "
87
- end,
88
- ]
89
-
90
59
  # Deal with the ^D key being pressed. Different behaviour in different cases:
91
60
  # 1. In an expression behave like `!` command.
92
61
  # 2. At top-level session behave like `exit` command.
@@ -112,10 +81,6 @@ class Pry
112
81
  end
113
82
  end
114
83
 
115
- # Store the current working directory. This allows show-source etc. to work if
116
- # your process has changed directory since boot. [Issue #675]
117
- INITIAL_PWD = Dir.pwd
118
-
119
84
  # This is to keep from breaking under Rails 3.2 for people who are doing that
120
85
  # IRB = Pry thing.
121
86
  module ExtendCommandBundle; end
@@ -124,17 +89,17 @@ end
124
89
  require 'method_source'
125
90
  require 'shellwords'
126
91
  require 'stringio'
92
+ require 'strscan'
127
93
  require 'coderay'
128
- require 'slop'
94
+ require 'pry/slop'
129
95
  require 'rbconfig'
130
96
  require 'tempfile'
131
97
  require 'pathname'
132
98
 
133
99
  require 'pry/version'
134
100
  require 'pry/repl'
135
- require 'pry/rbx_path'
136
101
  require 'pry/code'
137
- require 'pry/history_array'
102
+ require 'pry/ring'
138
103
  require 'pry/helpers'
139
104
  require 'pry/code_object'
140
105
  require 'pry/method'
@@ -145,6 +110,12 @@ require 'pry/command_set'
145
110
  require 'pry/commands'
146
111
  require 'pry/plugins'
147
112
  require 'pry/core_extensions'
113
+ require 'pry/basic_object'
114
+ require 'pry/config/behavior'
115
+ require 'pry/config/memoization'
116
+ require 'pry/config/default'
117
+ require 'pry/config/convenience'
118
+ require 'pry/config'
148
119
  require 'pry/pry_class'
149
120
  require 'pry/pry_instance'
150
121
  require 'pry/cli'