pry 0.11.1 → 0.12.0
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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +184 -1
- data/LICENSE +1 -1
- data/README.md +13 -30
- data/bin/pry +0 -4
- data/lib/pry/cli.rb +17 -24
- data/lib/pry/code/code_file.rb +5 -4
- data/lib/pry/code/code_range.rb +3 -3
- data/lib/pry/code/loc.rb +14 -8
- data/lib/pry/code.rb +6 -6
- data/lib/pry/code_object.rb +4 -4
- data/lib/pry/color_printer.rb +2 -1
- data/lib/pry/command.rb +36 -29
- data/lib/pry/command_set.rb +17 -52
- 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 +9 -8
- 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 +9 -9
- data/lib/pry/commands/easter_eggs.rb +3 -3
- data/lib/pry/commands/edit.rb +8 -7
- data/lib/pry/commands/exit.rb +2 -1
- data/lib/pry/commands/find_method.rb +11 -13
- 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 +1 -1
- data/lib/pry/commands/gem_search.rb +2 -2
- 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 +9 -8
- data/lib/pry/commands/import_set.rb +2 -1
- data/lib/pry/commands/install_command.rb +7 -6
- data/lib/pry/commands/list_inspectors.rb +2 -2
- data/lib/pry/commands/ls/constants.rb +4 -4
- data/lib/pry/commands/ls/formatter.rb +3 -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/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 +0 -1
- data/lib/pry/commands/ls.rb +27 -30
- data/lib/pry/commands/play.rb +1 -2
- data/lib/pry/commands/pry_backtrace.rb +1 -1
- data/lib/pry/commands/raise_up.rb +2 -1
- data/lib/pry/commands/ri.rb +5 -4
- data/lib/pry/commands/shell_command.rb +3 -2
- 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 +25 -18
- data/lib/pry/commands/show_source.rb +5 -2
- data/lib/pry/commands/stat.rb +1 -1
- data/lib/pry/commands/watch_expression.rb +9 -7
- data/lib/pry/commands/whereami.rb +5 -5
- data/lib/pry/commands/wtf.rb +15 -2
- data/lib/pry/config/behavior.rb +229 -204
- data/lib/pry/config/convenience.rb +24 -21
- data/lib/pry/config/default.rb +153 -143
- data/lib/pry/config/memoization.rb +41 -37
- data/lib/pry/config.rb +33 -9
- data/lib/pry/core_extensions.rb +4 -3
- data/lib/pry/editor.rb +5 -12
- data/lib/pry/exceptions.rb +0 -2
- data/lib/pry/helpers/base_helpers.rb +197 -106
- data/lib/pry/helpers/command_helpers.rb +5 -4
- data/lib/pry/helpers/documentation_helpers.rb +2 -2
- data/lib/pry/helpers/options_helpers.rb +5 -5
- data/lib/pry/helpers/platform.rb +58 -0
- data/lib/pry/helpers/table.rb +20 -15
- data/lib/pry/helpers/text.rb +23 -9
- data/lib/pry/helpers.rb +1 -0
- data/lib/pry/history.rb +21 -8
- data/lib/pry/hooks.rb +3 -3
- data/lib/pry/indent.rb +15 -17
- data/lib/pry/input_completer.rb +12 -7
- data/lib/pry/input_lock.rb +0 -2
- data/lib/pry/last_exception.rb +1 -1
- data/lib/pry/method/disowned.rb +2 -1
- data/lib/pry/method/patcher.rb +2 -2
- data/lib/pry/method/weird_method_locator.rb +21 -11
- data/lib/pry/method.rb +37 -31
- data/lib/pry/object_path.rb +5 -4
- data/lib/pry/output.rb +3 -2
- data/lib/pry/pager.rb +4 -3
- data/lib/pry/platform.rb +91 -0
- data/lib/pry/plugins.rb +7 -3
- data/lib/pry/prompt.rb +144 -25
- data/lib/pry/pry_class.rb +53 -29
- data/lib/pry/pry_instance.rb +88 -55
- data/lib/pry/repl.rb +33 -4
- data/lib/pry/repl_file_loader.rb +1 -2
- data/lib/pry/ring.rb +84 -0
- data/lib/pry/rubygem.rb +6 -6
- data/lib/pry/slop/commands.rb +3 -4
- data/lib/pry/slop/option.rb +19 -21
- data/lib/pry/slop.rb +17 -17
- data/lib/pry/terminal.rb +2 -1
- 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/wrapped_module/candidate.rb +2 -2
- data/lib/pry/wrapped_module.rb +15 -15
- data/lib/pry.rb +18 -47
- metadata +24 -30
- 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 -179
data/lib/pry/slop.rb
CHANGED
|
@@ -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
|
-
:
|
|
28
|
-
:
|
|
29
|
-
:
|
|
30
|
-
:
|
|
31
|
-
:
|
|
32
|
-
:
|
|
33
|
-
:
|
|
34
|
-
:
|
|
35
|
-
:
|
|
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.', :
|
|
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
|
data/lib/pry/terminal.rb
CHANGED
|
@@ -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::
|
|
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
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Pry::Testable::Evalable
|
|
2
|
+
def pry_tester(*args, &block)
|
|
3
|
+
if args.length == 0 || args[0].is_a?(Hash)
|
|
4
|
+
args.unshift(Pry.toplevel_binding)
|
|
5
|
+
end
|
|
6
|
+
Pry::Testable::PryTester.new(*args).tap do |t|
|
|
7
|
+
t.singleton_class.class_eval(&block) if block
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def pry_eval(*eval_strs)
|
|
12
|
+
b = String === eval_strs.first ? Pry.toplevel_binding : Pry.binding_for(eval_strs.shift)
|
|
13
|
+
pry_tester(b).eval(*eval_strs)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -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
|
@@ -2,7 +2,6 @@ require 'pry/helpers/documentation_helpers'
|
|
|
2
2
|
|
|
3
3
|
class Pry
|
|
4
4
|
class WrappedModule
|
|
5
|
-
|
|
6
5
|
# This class represents a single candidate for a module/class definition.
|
|
7
6
|
# It provides access to the source, documentation, line and file
|
|
8
7
|
# for a monkeypatch (reopening) of a class/module.
|
|
@@ -64,6 +63,7 @@ class Pry
|
|
|
64
63
|
# @return [String] The documentation for the candidate.
|
|
65
64
|
def doc
|
|
66
65
|
return nil if file.nil?
|
|
66
|
+
|
|
67
67
|
@doc ||= get_comment_content(Pry::Code.from_file(file).comment_describing(line))
|
|
68
68
|
end
|
|
69
69
|
|
|
@@ -76,7 +76,7 @@ class Pry
|
|
|
76
76
|
file, line = first_method_source_location
|
|
77
77
|
return nil if !file.is_a?(String)
|
|
78
78
|
|
|
79
|
-
@source_location = [file,
|
|
79
|
+
@source_location = [file, first_line_of_module_definition(file, line)]
|
|
80
80
|
rescue Pry::RescuableException
|
|
81
81
|
nil
|
|
82
82
|
end
|
data/lib/pry/wrapped_module.rb
CHANGED
|
@@ -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
|
|
@@ -49,6 +49,7 @@ class Pry
|
|
|
49
49
|
def safe_to_evaluate?(str, target)
|
|
50
50
|
return true if str.strip == "self"
|
|
51
51
|
return false if str =~ /%/
|
|
52
|
+
|
|
52
53
|
kind = target.eval("defined?(#{str})")
|
|
53
54
|
kind =~ /variable|constant/
|
|
54
55
|
end
|
|
@@ -58,6 +59,7 @@ class Pry
|
|
|
58
59
|
# @param [Module] mod
|
|
59
60
|
def initialize(mod)
|
|
60
61
|
raise ArgumentError, "Tried to initialize a WrappedModule with a non-module #{mod.inspect}" unless ::Module === mod
|
|
62
|
+
|
|
61
63
|
@wrapped = mod
|
|
62
64
|
@memoized_candidates = []
|
|
63
65
|
@host_file_lines = nil
|
|
@@ -109,10 +111,6 @@ class Pry
|
|
|
109
111
|
def singleton_class?
|
|
110
112
|
if Pry::Method.safe_send(wrapped, :respond_to?, :singleton_class?)
|
|
111
113
|
Pry::Method.safe_send(wrapped, :singleton_class?)
|
|
112
|
-
elsif defined?(Rubinius)
|
|
113
|
-
# https://github.com/rubinius/rubinius/commit/2e71722dba53d1a92c54d5e3968d64d1042486fe singleton_class? added 30 Jul 2014
|
|
114
|
-
# https://github.com/rubinius/rubinius/commit/4310f6b2ef3c8fc88135affe697db4e29e4621c4 has been around since 2011
|
|
115
|
-
!!Rubinius::Type.singleton_class_object(wrapped)
|
|
116
114
|
else
|
|
117
115
|
wrapped != Pry::Method.safe_send(wrapped, :ancestors).first
|
|
118
116
|
end
|
|
@@ -138,10 +136,10 @@ class Pry
|
|
|
138
136
|
def singleton_instance
|
|
139
137
|
raise ArgumentError, "tried to get instance of non singleton class" unless singleton_class?
|
|
140
138
|
|
|
141
|
-
if Helpers::
|
|
139
|
+
if Helpers::Platform.jruby?
|
|
142
140
|
wrapped.to_java.attached
|
|
143
141
|
else
|
|
144
|
-
@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 }
|
|
145
143
|
end
|
|
146
144
|
end
|
|
147
145
|
|
|
@@ -150,7 +148,7 @@ class Pry
|
|
|
150
148
|
wrapped.send(method_name, *args, &block)
|
|
151
149
|
end
|
|
152
150
|
|
|
153
|
-
def respond_to?(method_name, include_all=false)
|
|
151
|
+
def respond_to?(method_name, include_all = false)
|
|
154
152
|
super || wrapped.respond_to?(method_name, include_all)
|
|
155
153
|
end
|
|
156
154
|
|
|
@@ -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,16 +321,16 @@ 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
332
|
safe_send(mod, :constants).flat_map do |const_name|
|
|
335
|
-
if const = nested_module?(mod, const_name)
|
|
333
|
+
if (const = nested_module?(mod, const_name))
|
|
336
334
|
all_relevant_methods_for(const)
|
|
337
335
|
else
|
|
338
336
|
[]
|
|
@@ -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,10 +1,8 @@
|
|
|
1
|
-
# (C) John Mair (banisterfiend) 2016
|
|
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
8
|
|
|
@@ -12,6 +10,7 @@ class Pry
|
|
|
12
10
|
# The default hooks - display messages when beginning and ending Pry sessions.
|
|
13
11
|
DEFAULT_HOOKS = Pry::Hooks.new.add_hook(:before_session, :default) do |out, target, _pry_|
|
|
14
12
|
next if _pry_.quiet?
|
|
13
|
+
|
|
15
14
|
_pry_.run_command("whereami --quiet")
|
|
16
15
|
end
|
|
17
16
|
|
|
@@ -45,47 +44,18 @@ class Pry
|
|
|
45
44
|
else
|
|
46
45
|
output.puts "#{exception.class}: #{exception.message}"
|
|
47
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
|
|
48
56
|
end
|
|
49
57
|
end
|
|
50
58
|
|
|
51
|
-
DEFAULT_PROMPT_NAME = 'pry'
|
|
52
|
-
|
|
53
|
-
# The default prompt; includes the target and nesting level
|
|
54
|
-
DEFAULT_PROMPT = [
|
|
55
|
-
proc { |target_self, nest_level, pry|
|
|
56
|
-
"[#{pry.input_array.size}] #{pry.config.prompt_name}(#{Pry.view_clip(target_self)})#{":#{nest_level}" unless nest_level.zero?}> "
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
proc { |target_self, nest_level, pry|
|
|
60
|
-
"[#{pry.input_array.size}] #{pry.config.prompt_name}(#{Pry.view_clip(target_self)})#{":#{nest_level}" unless nest_level.zero?}* "
|
|
61
|
-
}
|
|
62
|
-
]
|
|
63
|
-
|
|
64
|
-
DEFAULT_PROMPT_SAFE_OBJECTS = [String, Numeric, Symbol, nil, true, false]
|
|
65
|
-
|
|
66
|
-
# A simple prompt - doesn't display target or nesting level
|
|
67
|
-
SIMPLE_PROMPT = [proc { ">> " }, proc { " | " }]
|
|
68
|
-
|
|
69
|
-
NO_PROMPT = [proc { '' }, proc { '' }]
|
|
70
|
-
|
|
71
|
-
SHELL_PROMPT = [
|
|
72
|
-
proc { |target_self, _, _pry_| "#{_pry_.config.prompt_name} #{Pry.view_clip(target_self)}:#{Dir.pwd} $ " },
|
|
73
|
-
proc { |target_self, _, _pry_| "#{_pry_.config.prompt_name} #{Pry.view_clip(target_self)}:#{Dir.pwd} * " }
|
|
74
|
-
]
|
|
75
|
-
|
|
76
|
-
# A prompt that includes the full object path as well as
|
|
77
|
-
# input/output (_in_ and _out_) information. Good for navigation.
|
|
78
|
-
NAV_PROMPT = [
|
|
79
|
-
proc do |_, _, _pry_|
|
|
80
|
-
tree = _pry_.binding_stack.map { |b| Pry.view_clip(b.eval("self")) }.join " / "
|
|
81
|
-
"[#{_pry_.input_array.count}] (#{_pry_.config.prompt_name}) #{tree}: #{_pry_.binding_stack.size - 1}> "
|
|
82
|
-
end,
|
|
83
|
-
proc do |_, _, _pry_|
|
|
84
|
-
tree = _pry_.binding_stack.map { |b| Pry.view_clip(b.eval("self")) }.join " / "
|
|
85
|
-
"[#{_pry_.input_array.count}] (#{ _pry_.config.prompt_name}) #{tree}: #{_pry_.binding_stack.size - 1}* "
|
|
86
|
-
end,
|
|
87
|
-
]
|
|
88
|
-
|
|
89
59
|
# Deal with the ^D key being pressed. Different behaviour in different cases:
|
|
90
60
|
# 1. In an expression behave like `!` command.
|
|
91
61
|
# 2. At top-level session behave like `exit` command.
|
|
@@ -111,10 +81,6 @@ class Pry
|
|
|
111
81
|
end
|
|
112
82
|
end
|
|
113
83
|
|
|
114
|
-
# Store the current working directory. This allows show-source etc. to work if
|
|
115
|
-
# your process has changed directory since boot. [Issue #675]
|
|
116
|
-
INITIAL_PWD = Dir.pwd
|
|
117
|
-
|
|
118
84
|
# This is to keep from breaking under Rails 3.2 for people who are doing that
|
|
119
85
|
# IRB = Pry thing.
|
|
120
86
|
module ExtendCommandBundle; end
|
|
@@ -132,9 +98,8 @@ 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'
|