pry 0.10.4 → 0.12.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +251 -16
- data/LICENSE +1 -1
- data/README.md +35 -51
- data/bin/pry +3 -11
- data/lib/pry/basic_object.rb +6 -0
- data/lib/pry/cli.rb +50 -52
- data/lib/pry/code/code_file.rb +13 -6
- data/lib/pry/code/code_range.rb +3 -3
- data/lib/pry/code/loc.rb +14 -8
- data/lib/pry/code.rb +11 -6
- data/lib/pry/code_object.rb +27 -4
- data/lib/pry/color_printer.rb +20 -10
- data/lib/pry/command.rb +76 -45
- data/lib/pry/command_set.rb +17 -45
- data/lib/pry/commands/amend_line.rb +3 -4
- data/lib/pry/commands/bang.rb +1 -1
- data/lib/pry/commands/cat/exception_formatter.rb +10 -8
- data/lib/pry/commands/cat/file_formatter.rb +7 -3
- data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
- data/lib/pry/commands/cat.rb +7 -6
- data/lib/pry/commands/change_prompt.rb +29 -9
- data/lib/pry/commands/clear_screen.rb +14 -0
- data/lib/pry/commands/code_collector.rb +25 -23
- data/lib/pry/commands/easter_eggs.rb +12 -12
- data/lib/pry/commands/edit/file_and_line_locator.rb +1 -1
- data/lib/pry/commands/edit.rb +15 -10
- data/lib/pry/commands/exit.rb +2 -1
- data/lib/pry/commands/find_method.rb +12 -14
- data/lib/pry/commands/gem_cd.rb +1 -1
- data/lib/pry/commands/gem_install.rb +2 -2
- data/lib/pry/commands/gem_list.rb +2 -2
- data/lib/pry/commands/gem_open.rb +2 -2
- data/lib/pry/commands/gem_readme.rb +25 -0
- data/lib/pry/commands/gem_search.rb +40 -0
- data/lib/pry/commands/gem_stats.rb +83 -0
- data/lib/pry/commands/gist.rb +7 -6
- data/lib/pry/commands/help.rb +3 -3
- data/lib/pry/commands/hist.rb +11 -10
- data/lib/pry/commands/import_set.rb +2 -1
- data/lib/pry/commands/install_command.rb +7 -6
- data/lib/pry/commands/jump_to.rb +7 -7
- data/lib/pry/commands/list_inspectors.rb +2 -2
- data/lib/pry/commands/ls/constants.rb +14 -3
- data/lib/pry/commands/ls/formatter.rb +4 -2
- data/lib/pry/commands/ls/globals.rb +0 -2
- data/lib/pry/commands/ls/grep.rb +0 -2
- data/lib/pry/commands/ls/instance_vars.rb +0 -1
- data/lib/pry/commands/ls/jruby_hacks.rb +2 -2
- data/lib/pry/commands/ls/local_names.rb +0 -2
- data/lib/pry/commands/ls/local_vars.rb +0 -2
- data/lib/pry/commands/ls/ls_entity.rb +0 -1
- data/lib/pry/commands/ls/methods.rb +0 -3
- data/lib/pry/commands/ls/methods_helper.rb +1 -1
- data/lib/pry/commands/ls/self_methods.rb +2 -1
- data/lib/pry/commands/ls.rb +30 -31
- data/lib/pry/commands/play.rb +3 -4
- data/lib/pry/commands/pry_backtrace.rb +1 -1
- data/lib/pry/commands/raise_up.rb +2 -1
- data/lib/pry/commands/reload_code.rb +2 -2
- data/lib/pry/commands/ri.rb +9 -4
- data/lib/pry/commands/shell_command.rb +36 -9
- data/lib/pry/commands/shell_mode.rb +6 -6
- data/lib/pry/commands/show_doc.rb +5 -7
- data/lib/pry/commands/show_info.rb +35 -20
- data/lib/pry/commands/show_source.rb +5 -2
- data/lib/pry/commands/stat.rb +1 -1
- data/lib/pry/commands/watch_expression/expression.rb +1 -1
- data/lib/pry/commands/watch_expression.rb +9 -7
- data/lib/pry/commands/whereami.rb +11 -10
- data/lib/pry/commands/wtf.rb +15 -2
- data/lib/pry/config/behavior.rb +230 -114
- data/lib/pry/config/convenience.rb +24 -21
- data/lib/pry/config/default.rb +151 -153
- data/lib/pry/config/memoization.rb +48 -0
- data/lib/pry/config.rb +30 -19
- data/lib/pry/core_extensions.rb +15 -4
- data/lib/pry/editor.rb +5 -12
- data/lib/pry/exceptions.rb +1 -3
- data/lib/pry/forwardable.rb +23 -0
- data/lib/pry/helpers/base_helpers.rb +197 -110
- data/lib/pry/helpers/command_helpers.rb +5 -4
- data/lib/pry/helpers/documentation_helpers.rb +3 -2
- data/lib/pry/helpers/options_helpers.rb +6 -6
- data/lib/pry/helpers/platform.rb +58 -0
- data/lib/pry/helpers/table.rb +20 -15
- data/lib/pry/helpers/text.rb +82 -74
- data/lib/pry/helpers.rb +1 -0
- data/lib/pry/history.rb +43 -9
- data/lib/pry/hooks.rb +50 -109
- data/lib/pry/indent.rb +21 -19
- data/lib/pry/input_completer.rb +146 -123
- data/lib/pry/input_lock.rb +0 -2
- data/lib/pry/last_exception.rb +2 -2
- data/lib/pry/method/disowned.rb +3 -1
- data/lib/pry/method/patcher.rb +2 -5
- data/lib/pry/method/weird_method_locator.rb +21 -11
- data/lib/pry/method.rb +44 -38
- data/lib/pry/object_path.rb +5 -4
- data/lib/pry/output.rb +37 -37
- data/lib/pry/pager.rb +195 -184
- data/lib/pry/platform.rb +91 -0
- data/lib/pry/plugins.rb +27 -8
- data/lib/pry/prompt.rb +144 -25
- data/lib/pry/pry_class.rb +83 -33
- data/lib/pry/pry_instance.rb +94 -59
- data/lib/pry/repl.rb +70 -11
- data/lib/pry/repl_file_loader.rb +2 -3
- data/lib/pry/ring.rb +84 -0
- data/lib/pry/rubygem.rb +9 -7
- data/lib/pry/slop/LICENSE +20 -0
- data/lib/pry/slop/commands.rb +195 -0
- data/lib/pry/slop/option.rb +206 -0
- data/lib/pry/slop.rb +661 -0
- data/lib/pry/terminal.rb +18 -6
- data/lib/pry/testable/evalable.rb +15 -0
- data/lib/pry/testable/mockable.rb +14 -0
- data/lib/pry/testable/pry_tester.rb +73 -0
- data/lib/pry/testable/utility.rb +26 -0
- data/lib/pry/testable/variables.rb +46 -0
- data/lib/pry/testable.rb +70 -0
- data/lib/pry/version.rb +1 -1
- data/lib/pry/{module_candidate.rb → wrapped_module/candidate.rb} +8 -14
- data/lib/pry/wrapped_module.rb +21 -21
- data/lib/pry.rb +21 -50
- metadata +29 -40
- data/lib/pry/commands/list_prompts.rb +0 -35
- data/lib/pry/commands/simple_prompt.rb +0 -22
- data/lib/pry/history_array.rb +0 -121
- data/lib/pry/rbx_path.rb +0 -22
- 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
|
data/lib/pry/testable.rb
ADDED
@@ -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,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
|
-
|
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, *
|
32
|
-
|
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
|
@@ -61,16 +56,15 @@ class Pry
|
|
61
56
|
return nil if file.nil?
|
62
57
|
return @source if @source
|
63
58
|
|
64
|
-
@source
|
59
|
+
@source ||= strip_leading_whitespace(Pry::Code.from_file(file).expression_at(line, number_of_lines_in_first_chunk))
|
65
60
|
end
|
66
61
|
|
67
62
|
# @raise [Pry::CommandError] If documentation cannot be found.
|
68
63
|
# @return [String] The documentation for the candidate.
|
69
64
|
def doc
|
70
65
|
return nil if file.nil?
|
71
|
-
return @doc if @doc
|
72
66
|
|
73
|
-
@doc
|
67
|
+
@doc ||= get_comment_content(Pry::Code.from_file(file).comment_describing(line))
|
74
68
|
end
|
75
69
|
|
76
70
|
# @return [Array, nil] A `[String, Fixnum]` pair representing the
|
@@ -82,7 +76,7 @@ class Pry
|
|
82
76
|
file, line = first_method_source_location
|
83
77
|
return nil if !file.is_a?(String)
|
84
78
|
|
85
|
-
@source_location = [file,
|
79
|
+
@source_location = [file, first_line_of_module_definition(file, line)]
|
86
80
|
rescue Pry::RescuableException
|
87
81
|
nil
|
88
82
|
end
|
data/lib/pry/wrapped_module.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'pry/
|
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,6 +59,7 @@ 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
|
@@ -108,10 +111,6 @@ class Pry
|
|
108
111
|
def singleton_class?
|
109
112
|
if Pry::Method.safe_send(wrapped, :respond_to?, :singleton_class?)
|
110
113
|
Pry::Method.safe_send(wrapped, :singleton_class?)
|
111
|
-
elsif defined?(Rubinius)
|
112
|
-
# https://github.com/rubinius/rubinius/commit/2e71722dba53d1a92c54d5e3968d64d1042486fe singleton_class? added 30 Jul 2014
|
113
|
-
# https://github.com/rubinius/rubinius/commit/4310f6b2ef3c8fc88135affe697db4e29e4621c4 has been around since 2011
|
114
|
-
!!Rubinius::Type.singleton_class_object(wrapped)
|
115
114
|
else
|
116
115
|
wrapped != Pry::Method.safe_send(wrapped, :ancestors).first
|
117
116
|
end
|
@@ -137,10 +136,10 @@ class Pry
|
|
137
136
|
def singleton_instance
|
138
137
|
raise ArgumentError, "tried to get instance of non singleton class" unless singleton_class?
|
139
138
|
|
140
|
-
if Helpers::
|
139
|
+
if Helpers::Platform.jruby?
|
141
140
|
wrapped.to_java.attached
|
142
141
|
else
|
143
|
-
@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 }
|
144
143
|
end
|
145
144
|
end
|
146
145
|
|
@@ -149,15 +148,14 @@ class Pry
|
|
149
148
|
wrapped.send(method_name, *args, &block)
|
150
149
|
end
|
151
150
|
|
152
|
-
def respond_to?(method_name)
|
153
|
-
super || wrapped.respond_to?(method_name)
|
151
|
+
def respond_to?(method_name, include_all = false)
|
152
|
+
super || wrapped.respond_to?(method_name, include_all)
|
154
153
|
end
|
155
154
|
|
156
155
|
# Retrieve the source location of a module. Return value is in same
|
157
156
|
# format as Method#source_location. If the source location
|
158
157
|
# cannot be found this method returns `nil`.
|
159
158
|
#
|
160
|
-
# @param [Module] mod The module (or class).
|
161
159
|
# @return [Array<String, Fixnum>, nil] The source location of the
|
162
160
|
# module (or class), or `nil` if no source location found.
|
163
161
|
def source_location
|
@@ -232,7 +230,7 @@ class Pry
|
|
232
230
|
# @param [Fixnum] rank
|
233
231
|
# @return [Pry::WrappedModule::Candidate]
|
234
232
|
def candidate(rank)
|
235
|
-
@memoized_candidates[rank] ||= Candidate.new(self, rank)
|
233
|
+
@memoized_candidates[rank] ||= WrappedModule::Candidate.new(self, rank)
|
236
234
|
end
|
237
235
|
|
238
236
|
# @return [Fixnum] The number of candidate definitions for the
|
@@ -253,7 +251,7 @@ class Pry
|
|
253
251
|
y.yield candidate(num)
|
254
252
|
end
|
255
253
|
end
|
256
|
-
|
254
|
+
Helpers::Platform.jruby_19? ? enum.to_a : enum
|
257
255
|
end
|
258
256
|
|
259
257
|
# @return [Boolean] Whether YARD docs are available for this module.
|
@@ -267,7 +265,7 @@ class Pry
|
|
267
265
|
# When `self` is a `Module` then return the
|
268
266
|
# nth ancestor, otherwise (in the case of classes) return the
|
269
267
|
# nth ancestor that is a class.
|
270
|
-
def super(times=1)
|
268
|
+
def super(times = 1)
|
271
269
|
return self if times.zero?
|
272
270
|
|
273
271
|
if wrapped.is_a?(Class)
|
@@ -302,7 +300,7 @@ class Pry
|
|
302
300
|
# speed up source code extraction.
|
303
301
|
def method_candidates
|
304
302
|
@method_candidates ||= all_source_locations_by_popularity.map do |group|
|
305
|
-
methods_sorted_by_source_line
|
303
|
+
methods_sorted_by_source_line = group.last.sort_by(&:source_line)
|
306
304
|
[methods_sorted_by_source_line.first, methods_sorted_by_source_line.last]
|
307
305
|
end
|
308
306
|
end
|
@@ -315,7 +313,7 @@ class Pry
|
|
315
313
|
@all_source_locations_by_popularity = ims.group_by { |v| Array(v.source_location).first }.
|
316
314
|
sort_by do |path, methods|
|
317
315
|
expanded = File.expand_path(path)
|
318
|
-
load_order = $LOADED_FEATURES.index{ |file| expanded.end_with?(file) }
|
316
|
+
load_order = $LOADED_FEATURES.index { |file| expanded.end_with?(file) }
|
319
317
|
|
320
318
|
[-methods.size, load_order || (1.0 / 0.0)]
|
321
319
|
end
|
@@ -323,21 +321,21 @@ class Pry
|
|
323
321
|
|
324
322
|
# We only want methods that have a non-nil `source_location`. We also
|
325
323
|
# skip some spooky internal methods.
|
326
|
-
#
|
324
|
+
#
|
327
325
|
# @return [Array<Pry::Method>]
|
328
326
|
def all_relevant_methods_for(mod)
|
329
327
|
methods = all_methods_for(mod).select(&:source_location).
|
330
|
-
reject{ |x|
|
328
|
+
reject { |x| method_defined_by_forwardable_module?(x) }
|
331
329
|
|
332
330
|
return methods unless methods.empty?
|
333
331
|
|
334
|
-
safe_send(mod, :constants).
|
335
|
-
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))
|
336
334
|
all_relevant_methods_for(const)
|
337
335
|
else
|
338
336
|
[]
|
339
337
|
end
|
340
|
-
end
|
338
|
+
end
|
341
339
|
end
|
342
340
|
|
343
341
|
# Return all methods (instance methods and class methods) for a
|
@@ -349,9 +347,11 @@ class Pry
|
|
349
347
|
|
350
348
|
def nested_module?(parent, name)
|
351
349
|
return if safe_send(parent, :autoload?, name)
|
350
|
+
|
352
351
|
child = safe_send(parent, :const_get, name)
|
353
352
|
return unless Module === child
|
354
353
|
return unless safe_send(child, :name) == "#{safe_send(parent, :name)}::#{name}"
|
354
|
+
|
355
355
|
child
|
356
356
|
end
|
357
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/
|
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'
|