pry 0.10.2-i386-mswin32 → 1.0.0.pre1-i386-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +2 -0
- data/.gitignore +16 -0
- data/.travis.yml +21 -0
- data/.yardopts +3 -0
- data/CHANGELOG +503 -0
- data/CONTRIBUTORS +55 -0
- data/Gemfile +9 -0
- data/Guardfile +62 -0
- data/LICENSE +2 -2
- data/{README.md → README.markdown} +31 -37
- data/Rakefile +144 -0
- data/TODO +117 -0
- data/lib/pry.rb +146 -33
- data/lib/pry/cli.rb +13 -35
- data/lib/pry/code.rb +63 -24
- data/lib/pry/code/loc.rb +2 -2
- data/lib/pry/code_object.rb +21 -40
- data/lib/pry/command.rb +6 -9
- data/lib/pry/command_set.rb +37 -80
- data/lib/pry/commands.rb +1 -1
- data/lib/pry/commands/amend_line.rb +1 -1
- data/lib/pry/commands/bang.rb +1 -1
- data/lib/pry/commands/cat.rb +2 -11
- data/lib/pry/commands/cat/abstract_formatter.rb +1 -1
- data/lib/pry/commands/cat/exception_formatter.rb +7 -6
- data/lib/pry/commands/cat/file_formatter.rb +32 -15
- data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
- data/lib/pry/commands/cd.rb +3 -14
- data/lib/pry/commands/code_collector.rb +4 -4
- data/lib/pry/commands/easter_eggs.rb +3 -3
- data/lib/pry/commands/edit.rb +22 -10
- data/lib/pry/commands/edit/exception_patcher.rb +1 -1
- data/lib/pry/commands/edit/file_and_line_locator.rb +2 -0
- data/lib/pry/{method/patcher.rb → commands/edit/method_patcher.rb} +37 -40
- data/lib/pry/commands/find_method.rb +22 -16
- data/lib/pry/commands/gem_install.rb +2 -5
- data/lib/pry/commands/gem_open.rb +1 -1
- data/lib/pry/commands/gist.rb +11 -10
- data/lib/pry/commands/help.rb +14 -14
- data/lib/pry/commands/hist.rb +5 -24
- data/lib/pry/commands/ls.rb +287 -56
- data/lib/pry/commands/play.rb +10 -44
- data/lib/pry/commands/pry_backtrace.rb +2 -1
- data/lib/pry/commands/raise_up.rb +1 -1
- data/lib/pry/commands/reload_code.rb +15 -31
- data/lib/pry/commands/ri.rb +3 -7
- data/lib/pry/commands/shell_command.rb +12 -17
- data/lib/pry/commands/shell_mode.rb +2 -2
- data/lib/pry/commands/show_doc.rb +0 -5
- data/lib/pry/commands/show_info.rb +10 -11
- data/lib/pry/commands/show_source.rb +3 -15
- data/lib/pry/commands/simple_prompt.rb +1 -1
- data/lib/pry/commands/toggle_color.rb +4 -8
- data/lib/pry/commands/whereami.rb +10 -18
- data/lib/pry/completion.rb +293 -0
- data/lib/pry/config.rb +233 -20
- data/lib/pry/core_extensions.rb +19 -29
- data/lib/pry/custom_completions.rb +6 -0
- data/lib/pry/editor.rb +103 -109
- data/lib/pry/helpers/base_helpers.rb +109 -22
- data/lib/pry/helpers/command_helpers.rb +8 -10
- data/lib/pry/helpers/documentation_helpers.rb +2 -1
- data/lib/pry/helpers/text.rb +5 -4
- data/lib/pry/history.rb +10 -21
- data/lib/pry/history_array.rb +0 -5
- data/lib/pry/hooks.rb +29 -9
- data/lib/pry/indent.rb +10 -5
- data/lib/pry/method.rb +86 -81
- data/lib/pry/method/weird_method_locator.rb +2 -4
- data/lib/pry/module_candidate.rb +14 -5
- data/lib/pry/pager.rb +48 -193
- data/lib/pry/plugins.rb +2 -2
- data/lib/pry/pry_class.rb +193 -104
- data/lib/pry/pry_instance.rb +154 -152
- data/lib/pry/rbx_method.rb +13 -0
- data/lib/pry/rbx_path.rb +1 -1
- data/lib/pry/repl.rb +14 -17
- data/lib/pry/repl_file_loader.rb +3 -8
- data/lib/pry/rubygem.rb +3 -3
- data/lib/pry/terminal.rb +3 -4
- data/lib/pry/test/helper.rb +11 -6
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +56 -49
- data/man/pry.1 +195 -0
- data/man/pry.1.html +204 -0
- data/man/pry.1.ronn +141 -0
- data/pry.gemspec +31 -0
- data/spec/Procfile +3 -0
- data/spec/cli_spec.rb +78 -0
- data/spec/code_object_spec.rb +277 -0
- data/spec/code_spec.rb +219 -0
- data/spec/command_helpers_spec.rb +29 -0
- data/spec/command_integration_spec.rb +562 -0
- data/spec/command_set_spec.rb +627 -0
- data/spec/command_spec.rb +821 -0
- data/spec/commands/amend_line_spec.rb +247 -0
- data/spec/commands/bang_spec.rb +18 -0
- data/spec/commands/cat_spec.rb +164 -0
- data/spec/commands/cd_spec.rb +250 -0
- data/spec/commands/disable_pry_spec.rb +25 -0
- data/spec/commands/edit_spec.rb +725 -0
- data/spec/commands/exit_all_spec.rb +27 -0
- data/spec/commands/exit_program_spec.rb +19 -0
- data/spec/commands/exit_spec.rb +28 -0
- data/spec/commands/find_method_spec.rb +70 -0
- data/spec/commands/gem_list_spec.rb +26 -0
- data/spec/commands/gist_spec.rb +79 -0
- data/spec/commands/help_spec.rb +56 -0
- data/spec/commands/hist_spec.rb +172 -0
- data/spec/commands/jump_to_spec.rb +15 -0
- data/spec/commands/ls_spec.rb +189 -0
- data/spec/commands/play_spec.rb +136 -0
- data/spec/commands/raise_up_spec.rb +56 -0
- data/spec/commands/save_file_spec.rb +177 -0
- data/spec/commands/show_doc_spec.rb +488 -0
- data/spec/commands/show_input_spec.rb +17 -0
- data/spec/commands/show_source_spec.rb +760 -0
- data/spec/commands/whereami_spec.rb +203 -0
- data/spec/completion_spec.rb +221 -0
- data/spec/control_d_handler_spec.rb +62 -0
- data/spec/documentation_helper_spec.rb +73 -0
- data/spec/editor_spec.rb +79 -0
- data/spec/exception_whitelist_spec.rb +21 -0
- data/spec/fixtures/candidate_helper1.rb +11 -0
- data/spec/fixtures/candidate_helper2.rb +8 -0
- data/spec/fixtures/example.erb +5 -0
- data/spec/fixtures/example_nesting.rb +33 -0
- data/spec/fixtures/show_source_doc_examples.rb +15 -0
- data/spec/fixtures/testlinkrc +2 -0
- data/spec/fixtures/testrc +2 -0
- data/spec/fixtures/testrcbad +2 -0
- data/spec/fixtures/whereami_helper.rb +6 -0
- data/spec/helper.rb +35 -0
- data/spec/helpers/bacon.rb +86 -0
- data/spec/helpers/mock_pry.rb +44 -0
- data/spec/helpers/repl_tester.rb +112 -0
- data/spec/helpers/table_spec.rb +105 -0
- data/spec/history_array_spec.rb +67 -0
- data/spec/hooks_spec.rb +522 -0
- data/spec/indent_spec.rb +301 -0
- data/spec/method_spec.rb +482 -0
- data/spec/prompt_spec.rb +61 -0
- data/spec/pry_defaults_spec.rb +420 -0
- data/spec/pry_history_spec.rb +69 -0
- data/spec/pry_output_spec.rb +95 -0
- data/spec/pry_repl_spec.rb +86 -0
- data/spec/pry_spec.rb +394 -0
- data/spec/pryrc_spec.rb +97 -0
- data/spec/run_command_spec.rb +25 -0
- data/spec/sticky_locals_spec.rb +147 -0
- data/spec/syntax_checking_spec.rb +81 -0
- data/spec/wrapped_module_spec.rb +261 -0
- data/wiki/Customizing-pry.md +397 -0
- data/wiki/Home.md +4 -0
- metadata +272 -61
- checksums.yaml +0 -7
- data/CHANGELOG.md +0 -714
- data/lib/pry/code/code_file.rb +0 -103
- data/lib/pry/color_printer.rb +0 -55
- data/lib/pry/commands/change_inspector.rb +0 -27
- data/lib/pry/commands/change_prompt.rb +0 -26
- data/lib/pry/commands/list_inspectors.rb +0 -35
- data/lib/pry/commands/list_prompts.rb +0 -35
- data/lib/pry/commands/ls/constants.rb +0 -47
- data/lib/pry/commands/ls/formatter.rb +0 -49
- data/lib/pry/commands/ls/globals.rb +0 -48
- data/lib/pry/commands/ls/grep.rb +0 -21
- data/lib/pry/commands/ls/instance_vars.rb +0 -39
- data/lib/pry/commands/ls/interrogatable.rb +0 -18
- data/lib/pry/commands/ls/jruby_hacks.rb +0 -49
- data/lib/pry/commands/ls/local_names.rb +0 -35
- data/lib/pry/commands/ls/local_vars.rb +0 -39
- data/lib/pry/commands/ls/ls_entity.rb +0 -70
- data/lib/pry/commands/ls/methods.rb +0 -57
- data/lib/pry/commands/ls/methods_helper.rb +0 -46
- data/lib/pry/commands/ls/self_methods.rb +0 -32
- data/lib/pry/commands/watch_expression.rb +0 -105
- data/lib/pry/commands/watch_expression/expression.rb +0 -38
- data/lib/pry/config/behavior.rb +0 -139
- data/lib/pry/config/convenience.rb +0 -25
- data/lib/pry/config/default.rb +0 -161
- data/lib/pry/exceptions.rb +0 -78
- data/lib/pry/input_completer.rb +0 -242
- data/lib/pry/input_lock.rb +0 -132
- data/lib/pry/inspector.rb +0 -27
- data/lib/pry/last_exception.rb +0 -61
- data/lib/pry/object_path.rb +0 -82
- data/lib/pry/output.rb +0 -50
- data/lib/pry/prompt.rb +0 -26
@@ -15,6 +15,14 @@ class Pry
|
|
15
15
|
file.close(true) if file
|
16
16
|
end
|
17
17
|
|
18
|
+
def render_output(str, opts={})
|
19
|
+
if opts[:flood]
|
20
|
+
output.puts str
|
21
|
+
else
|
22
|
+
stagger_output str
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
18
26
|
def internal_binding?(target)
|
19
27
|
m = target.eval("::Kernel.__method__").to_s
|
20
28
|
# class_eval is here because of http://jira.codehaus.org/browse/JRUBY-6753
|
@@ -141,16 +149,6 @@ class Pry
|
|
141
149
|
|
142
150
|
Range.new(a, b)
|
143
151
|
end
|
144
|
-
|
145
|
-
def set_file_and_dir_locals(file_name, _pry_=_pry_(), target=target())
|
146
|
-
return if !target or !file_name
|
147
|
-
_pry_.last_file = File.expand_path(file_name)
|
148
|
-
_pry_.inject_local("_file_", _pry_.last_file, target)
|
149
|
-
|
150
|
-
_pry_.last_dir = File.dirname(_pry_.last_file)
|
151
|
-
_pry_.inject_local("_dir_", _pry_.last_dir, target)
|
152
|
-
end
|
153
152
|
end
|
154
|
-
|
155
153
|
end
|
156
154
|
end
|
@@ -8,6 +8,7 @@ class Pry
|
|
8
8
|
module_function
|
9
9
|
|
10
10
|
def process_rdoc(comment)
|
11
|
+
return comment unless Pry.color
|
11
12
|
comment = comment.dup
|
12
13
|
comment.gsub(/<code>(?:\s*\n)?(.*?)\s*<\/code>/m) { CodeRay.scan($1, :ruby).term }.
|
13
14
|
gsub(/<em>(?:\s*\n)?(.*?)\s*<\/em>/m) { "\e[1m#{$1}\e[0m" }.
|
@@ -36,7 +37,7 @@ class Pry
|
|
36
37
|
yard_tags = ["param", "return", "option", "yield", "attr", "attr_reader", "attr_writer",
|
37
38
|
"deprecate", "example", "raise"]
|
38
39
|
(yard_tags - ["example"]).inject(comment) { |a, v| process_yardoc_tag(a, v) }.
|
39
|
-
gsub(/^@(#{yard_tags.join("|")})/) { "\e[33m#{$1}\e[0m" }
|
40
|
+
gsub(/^@(#{yard_tags.join("|")})/) { Pry.color ? "\e[33m#{$1}\e[0m": $1 }
|
40
41
|
end
|
41
42
|
|
42
43
|
def process_comment_markup(comment)
|
data/lib/pry/helpers/text.rb
CHANGED
@@ -21,11 +21,11 @@ class Pry
|
|
21
21
|
|
22
22
|
COLORS.each_pair do |color, value|
|
23
23
|
define_method color do |text|
|
24
|
-
"\033[0;#{30+value}m#{text}\033[0m"
|
24
|
+
Pry.color ? "\033[0;#{30+value}m#{text}\033[0m" : text.to_s
|
25
25
|
end
|
26
26
|
|
27
27
|
define_method "bright_#{color}" do |text|
|
28
|
-
"\033[1;#{30+value}m#{text}\033[0m"
|
28
|
+
Pry.color ? "\033[1;#{30+value}m#{text}\033[0m" : text.to_s
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -38,11 +38,12 @@ class Pry
|
|
38
38
|
end
|
39
39
|
|
40
40
|
# Returns _text_ as bold text for use on a terminal.
|
41
|
+
# _Pry.color_ must be true for this method to perform any transformations.
|
41
42
|
#
|
42
43
|
# @param [String, #to_s] text
|
43
44
|
# @return [String] _text_
|
44
45
|
def bold(text)
|
45
|
-
"\e[1m#{text}\e[0m"
|
46
|
+
Pry.color ? "\e[1m#{text}\e[0m" : text.to_s
|
46
47
|
end
|
47
48
|
|
48
49
|
# Returns `text` in the default foreground colour.
|
@@ -55,7 +56,7 @@ class Pry
|
|
55
56
|
end
|
56
57
|
alias_method :bright_default, :bold
|
57
58
|
|
58
|
-
# Executes the block with `Pry.
|
59
|
+
# Executes the block with `Pry.color` set to false.
|
59
60
|
# @yield
|
60
61
|
# @return [void]
|
61
62
|
def no_color(&block)
|
data/lib/pry/history.rb
CHANGED
@@ -16,18 +16,10 @@ class Pry
|
|
16
16
|
|
17
17
|
# Assign the default methods for loading, saving, pushing, and clearing.
|
18
18
|
def restore_default_behavior
|
19
|
-
|
20
|
-
|
21
|
-
@
|
22
|
-
@
|
23
|
-
|
24
|
-
if defined?(Readline)
|
25
|
-
@pusher = method(:push_to_readline)
|
26
|
-
@clearer = method(:clear_readline)
|
27
|
-
else
|
28
|
-
@pusher = proc { }
|
29
|
-
@clearer = proc { }
|
30
|
-
end
|
19
|
+
@loader = method(:read_from_file)
|
20
|
+
@saver = method(:save_to_file)
|
21
|
+
@pusher = method(:push_to_readline)
|
22
|
+
@clearer = method(:clear_readline)
|
31
23
|
end
|
32
24
|
|
33
25
|
# Load the input history using `History.loader`.
|
@@ -36,7 +28,6 @@ class Pry
|
|
36
28
|
@loader.call do |line|
|
37
29
|
@pusher.call(line.chomp)
|
38
30
|
@history << line.chomp
|
39
|
-
@original_lines += 1
|
40
31
|
end
|
41
32
|
end
|
42
33
|
|
@@ -81,10 +72,10 @@ class Pry
|
|
81
72
|
|
82
73
|
# The default loader. Yields lines from `Pry.history.config.file`.
|
83
74
|
def read_from_file
|
84
|
-
|
75
|
+
filename = File.expand_path(Pry.config.history.file)
|
85
76
|
|
86
|
-
if File.exists?(
|
87
|
-
File.foreach(
|
77
|
+
if File.exists?(filename)
|
78
|
+
File.foreach(filename) { |line| yield(line) }
|
88
79
|
end
|
89
80
|
rescue => error
|
90
81
|
warn "History file not loaded: #{error.message}"
|
@@ -111,17 +102,15 @@ class Pry
|
|
111
102
|
if defined?(@history_file)
|
112
103
|
@history_file
|
113
104
|
else
|
114
|
-
@history_file = File.open(
|
115
|
-
file.sync = true
|
116
|
-
end
|
105
|
+
@history_file = File.open(file_path, 'a').tap { |f| f.sync = true }
|
117
106
|
end
|
118
107
|
rescue Errno::EACCES
|
119
108
|
warn 'History not saved; unable to open your history file for writing.'
|
120
109
|
@history_file = false
|
121
110
|
end
|
122
111
|
|
123
|
-
def
|
124
|
-
|
112
|
+
def file_path
|
113
|
+
@file_path || Pry.config.history.file
|
125
114
|
end
|
126
115
|
end
|
127
116
|
end
|
data/lib/pry/history_array.rb
CHANGED
data/lib/pry/hooks.rb
CHANGED
@@ -18,11 +18,11 @@ class Pry
|
|
18
18
|
# @param [Hash] hash The hash to convert to `Pry::Hooks`.
|
19
19
|
# @return [Pry::Hooks] The resulting `Pry::Hooks` instance.
|
20
20
|
def self.from_hash(hash)
|
21
|
-
return hash if hash.instance_of?(self)
|
22
21
|
instance = new
|
23
22
|
hash.each do |k, v|
|
24
23
|
instance.add_hook(k, nil, v)
|
25
24
|
end
|
25
|
+
|
26
26
|
instance
|
27
27
|
end
|
28
28
|
|
@@ -49,6 +49,22 @@ class Pry
|
|
49
49
|
@errors ||= []
|
50
50
|
end
|
51
51
|
|
52
|
+
# FIXME:
|
53
|
+
# This is a hack to alert people of the new API.
|
54
|
+
def [](event_name)
|
55
|
+
warn "`Pry.hooks[]` is deprecated! Please use the new `Pry::Hooks` API! http://rubydoc.info/github/pry/pry/master/Pry/Hooks"
|
56
|
+
|
57
|
+
get_hook(event_name, nil)
|
58
|
+
end
|
59
|
+
|
60
|
+
# FIXME:
|
61
|
+
# This is a hack to alert people of the new API.
|
62
|
+
def []=(event_name, callable)
|
63
|
+
warn "`Pry.hooks[]=` is deprecated! Please use the new `Pry::Hooks` API! http://rubydoc.info/github/pry/pry/master/Pry/Hooks"
|
64
|
+
|
65
|
+
add_hook(event_name, nil, callable)
|
66
|
+
end
|
67
|
+
|
52
68
|
# Destructively merge the contents of two `Pry:Hooks` instances.
|
53
69
|
# @param [Pry::Hooks] other The `Pry::Hooks` instance to merge
|
54
70
|
# @return [Pry:Hooks] Returns the receiver.
|
@@ -130,14 +146,18 @@ class Pry
|
|
130
146
|
def exec_hook(event_name, *args, &block)
|
131
147
|
@hooks[event_name] ||= []
|
132
148
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
149
|
+
# silence warnings to get rid of 1.8's "warning: multiple values
|
150
|
+
# for a block parameter" warnings
|
151
|
+
Pry::Helpers::BaseHelpers.silence_warnings do
|
152
|
+
@hooks[event_name].map do |hook_name, callable|
|
153
|
+
begin
|
154
|
+
callable.call(*args, &block)
|
155
|
+
rescue RescuableException => e
|
156
|
+
errors << e
|
157
|
+
e
|
158
|
+
end
|
159
|
+
end.last
|
160
|
+
end
|
141
161
|
end
|
142
162
|
|
143
163
|
# Return the number of hook functions registered for the `event_name` event.
|
data/lib/pry/indent.rb
CHANGED
@@ -94,8 +94,8 @@ class Pry
|
|
94
94
|
indent = new
|
95
95
|
lines = str.split("\n")
|
96
96
|
n = line_number - 1
|
97
|
-
to_indent = lines[0...n]
|
98
|
-
indent.indent(to_indent.join("\n")
|
97
|
+
to_indent = lines[0...n] + (lines[n] || "").split("def").first(1)
|
98
|
+
indent.indent(to_indent.join("\n") + "\n")
|
99
99
|
indent.module_nesting
|
100
100
|
end
|
101
101
|
|
@@ -320,7 +320,7 @@ class Pry
|
|
320
320
|
# [ ["class", "Foo"], ["module", "Bar::Baz"], ["class <<", "self"] ]
|
321
321
|
#
|
322
322
|
# A nil value in the @module_nesting array happens in two places: either
|
323
|
-
# when @
|
323
|
+
# when @awaiting_token is true and we're still waiting for the string to
|
324
324
|
# fill that space, or when a parse was rejected.
|
325
325
|
#
|
326
326
|
# At the moment this function is quite restricted about what formats it will
|
@@ -341,7 +341,7 @@ class Pry
|
|
341
341
|
@module_nesting.last[1] = token if kind == :class
|
342
342
|
@awaiting_class = false
|
343
343
|
else
|
344
|
-
# leave @
|
344
|
+
# leave @nesting[-1][
|
345
345
|
@awaiting_class = false
|
346
346
|
end
|
347
347
|
end
|
@@ -384,7 +384,7 @@ class Pry
|
|
384
384
|
# @return [String]
|
385
385
|
def correct_indentation(prompt, code, overhang=0)
|
386
386
|
prompt = prompt.delete("\001\002")
|
387
|
-
line_to_measure = Pry::Helpers::Text.strip_color(prompt)
|
387
|
+
line_to_measure = Pry::Helpers::Text.strip_color(prompt) + code
|
388
388
|
whitespace = ' ' * overhang
|
389
389
|
|
390
390
|
_, cols = Terminal.screen_size
|
@@ -402,5 +402,10 @@ class Pry
|
|
402
402
|
|
403
403
|
"#{move_up}#{prompt}#{colorize_code(code)}#{whitespace}#{move_down}"
|
404
404
|
end
|
405
|
+
|
406
|
+
# Given the current Pry environment, should we try to correct indentation?
|
407
|
+
def should_correct_indentation?
|
408
|
+
Pry::Helpers::BaseHelpers.use_ansi_codes? && Pry.config.correct_indent
|
409
|
+
end
|
405
410
|
end
|
406
411
|
end
|
data/lib/pry/method.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
require 'pry/helpers/documentation_helpers'
|
2
3
|
|
3
4
|
class Pry
|
@@ -18,10 +19,10 @@ class Pry
|
|
18
19
|
class Method
|
19
20
|
require 'pry/method/weird_method_locator'
|
20
21
|
require 'pry/method/disowned'
|
21
|
-
require 'pry/method/patcher'
|
22
22
|
|
23
23
|
extend Helpers::BaseHelpers
|
24
24
|
include Helpers::BaseHelpers
|
25
|
+
include RbxMethod if rbx?
|
25
26
|
include Helpers::DocumentationHelpers
|
26
27
|
include CodeObject::Helpers
|
27
28
|
|
@@ -30,7 +31,8 @@ class Pry
|
|
30
31
|
# search in, find and return the requested method wrapped in a `Pry::Method`
|
31
32
|
# instance.
|
32
33
|
#
|
33
|
-
# @param [String] name The name of the method to retrieve
|
34
|
+
# @param [String, nil] name The name of the method to retrieve, or `nil` to
|
35
|
+
# delegate to `from_binding` instead.
|
34
36
|
# @param [Binding] target The context in which to search for the method.
|
35
37
|
# @param [Hash] options
|
36
38
|
# @option options [Boolean] :instance Look for an instance method if `name` doesn't
|
@@ -38,16 +40,13 @@ class Pry
|
|
38
40
|
# @option options [Boolean] :methods Look for a bound/singleton method if `name` doesn't
|
39
41
|
# contain any context.
|
40
42
|
# @return [Pry::Method, nil] A `Pry::Method` instance containing the requested
|
41
|
-
# method, or `nil` if
|
43
|
+
# method, or `nil` if no method could be located matching the parameters.
|
42
44
|
def from_str(name, target=TOPLEVEL_BINDING, options={})
|
43
45
|
if name.nil?
|
44
|
-
|
46
|
+
from_binding(target)
|
45
47
|
elsif name.to_s =~ /(.+)\#(\S+)\Z/
|
46
48
|
context, meth_name = $1, $2
|
47
49
|
from_module(target.eval(context), meth_name, target)
|
48
|
-
elsif name.to_s =~ /(.+)(\[\])\Z/
|
49
|
-
context, meth_name = $1, $2
|
50
|
-
from_obj(target.eval(context), meth_name, target)
|
51
50
|
elsif name.to_s =~ /(.+)(\.|::)(\S+)\Z/
|
52
51
|
context, meth_name = $1, $3
|
53
52
|
from_obj(target.eval(context), meth_name, target)
|
@@ -140,34 +139,15 @@ class Pry
|
|
140
139
|
# @param [Boolean] include_super Whether to include methods from ancestors.
|
141
140
|
# @return [Array[Pry::Method]]
|
142
141
|
def all_from_class(klass, include_super=true)
|
143
|
-
|
144
|
-
safe_send(klass, :"#{visibility}_instance_methods", include_super).map do |method_name|
|
145
|
-
new(safe_send(klass, :instance_method, method_name), :visibility => visibility.to_sym)
|
146
|
-
end
|
147
|
-
end.flatten(1)
|
142
|
+
all_from_common(klass, :instance_method, include_super)
|
148
143
|
end
|
149
144
|
|
150
|
-
#
|
151
145
|
# Get all of the methods on an `Object`
|
152
|
-
#
|
153
146
|
# @param [Object] obj
|
154
|
-
#
|
155
|
-
# @param [Boolean] include_super
|
156
|
-
# indicates whether or not to include methods from ancestors.
|
157
|
-
#
|
147
|
+
# @param [Boolean] include_super Whether to include methods from ancestors.
|
158
148
|
# @return [Array[Pry::Method]]
|
159
|
-
#
|
160
149
|
def all_from_obj(obj, include_super=true)
|
161
|
-
|
162
|
-
end
|
163
|
-
|
164
|
-
#
|
165
|
-
# @deprecated
|
166
|
-
# please use {#all_from_obj} instead.
|
167
|
-
# the `method_type` argument is ignored.
|
168
|
-
#
|
169
|
-
def all_from_common(obj, method_type = nil, include_super=true)
|
170
|
-
all_from_obj(obj, include_super)
|
150
|
+
all_from_common(obj, :method, include_super)
|
171
151
|
end
|
172
152
|
|
173
153
|
# Get every `Class` and `Module`, in order, that will be checked when looking
|
@@ -178,7 +158,7 @@ class Pry
|
|
178
158
|
if Class === obj
|
179
159
|
singleton_class_resolution_order(obj) + instance_resolution_order(Class)
|
180
160
|
else
|
181
|
-
klass =
|
161
|
+
klass = singleton_class(obj) rescue obj.class
|
182
162
|
instance_resolution_order(klass)
|
183
163
|
end
|
184
164
|
end
|
@@ -199,11 +179,26 @@ class Pry
|
|
199
179
|
end
|
200
180
|
|
201
181
|
def singleton_method_definition?(name, definition_line)
|
202
|
-
/^define_singleton_method\(?\s*[:\"\']#{
|
182
|
+
/^define_singleton_method\(?\s*[:\"\']#{name}|^def\s*self\.#{name}/ =~ definition_line.strip
|
203
183
|
end
|
204
184
|
|
205
185
|
def instance_method_definition?(name, definition_line)
|
206
|
-
/^define_method\(?\s*[:\"\']#{
|
186
|
+
/^define_method\(?\s*[:\"\']#{name}|^def\s*#{name}/ =~ definition_line.strip
|
187
|
+
end
|
188
|
+
|
189
|
+
private
|
190
|
+
|
191
|
+
# See all_from_class and all_from_obj.
|
192
|
+
# If method_type is :instance_method, obj must be a `Class` or a `Module`
|
193
|
+
# If method_type is :method, obj can be any `Object`
|
194
|
+
#
|
195
|
+
# N.B. we pre-cache the visibility here to avoid O(N²) behaviour in "ls".
|
196
|
+
def all_from_common(obj, method_type, include_super=true)
|
197
|
+
%w(public protected private).map do |visibility|
|
198
|
+
safe_send(obj, :"#{visibility}_#{method_type}s", include_super).map do |method_name|
|
199
|
+
new(safe_send(obj, method_type, method_name), :visibility => visibility.to_sym)
|
200
|
+
end
|
201
|
+
end.flatten(1)
|
207
202
|
end
|
208
203
|
|
209
204
|
# Get the singleton classes of superclasses that could define methods on
|
@@ -211,21 +206,14 @@ class Pry
|
|
211
206
|
# If a module is included at multiple points in the ancestry, only
|
212
207
|
# the lowest copy will be returned.
|
213
208
|
def singleton_class_resolution_order(klass)
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
end.flatten(1)
|
209
|
+
resolution_order = Pry::Method.safe_send(klass, :ancestors).map do |anc|
|
210
|
+
[singleton_class(anc)] + singleton_class(anc).included_modules if anc.is_a?(Class)
|
211
|
+
end.compact.flatten(1)
|
218
212
|
|
219
213
|
resolution_order.reverse.uniq.reverse - Class.included_modules
|
220
214
|
end
|
221
215
|
|
222
|
-
def
|
223
|
-
begin
|
224
|
-
class << obj; self; end
|
225
|
-
rescue TypeError # can't define singleton. Fixnum, Symbol, Float, ...
|
226
|
-
obj.class
|
227
|
-
end
|
228
|
-
end
|
216
|
+
def singleton_class(obj); class << obj; self; end end
|
229
217
|
end
|
230
218
|
|
231
219
|
# A new instance of `Pry::Method` wrapping the given `::Method`, `UnboundMethod`, or `Proc`.
|
@@ -275,18 +263,26 @@ class Pry
|
|
275
263
|
def source
|
276
264
|
@source ||= case source_type
|
277
265
|
when :c
|
278
|
-
|
266
|
+
info = pry_doc_info
|
267
|
+
if info and info.source
|
268
|
+
code = strip_comments_from_c_code(info.source)
|
269
|
+
end
|
279
270
|
when :ruby
|
280
|
-
|
271
|
+
# clone of MethodSource.source_helper that knows to use our
|
272
|
+
# hacked version of source_location for rbx core methods, and
|
273
|
+
# our input buffer for methods defined in (pry)
|
274
|
+
file, line = *source_location
|
275
|
+
raise SourceNotFoundError, "Could not locate source for #{name_with_owner}!" unless file
|
276
|
+
|
277
|
+
begin
|
278
|
+
code = Pry::Code.from_file(file).expression_at(line)
|
279
|
+
rescue SyntaxError => e
|
280
|
+
raise MethodSource::SourceNotFoundError.new(e.message)
|
281
|
+
end
|
282
|
+
strip_leading_whitespace(code)
|
281
283
|
end
|
282
284
|
end
|
283
285
|
|
284
|
-
# Update the live copy of the method's source.
|
285
|
-
def redefine(source)
|
286
|
-
Patcher.new(self).patch_in_ram source
|
287
|
-
Pry::Method(owner.instance_method(name))
|
288
|
-
end
|
289
|
-
|
290
286
|
# Can we get the source code for this method?
|
291
287
|
# @return [Boolean]
|
292
288
|
def source?
|
@@ -297,13 +293,20 @@ class Pry
|
|
297
293
|
|
298
294
|
# @return [String, nil] The documentation for the method, or `nil` if it's
|
299
295
|
# unavailable.
|
296
|
+
# @raise [CommandError] Raises when the method was defined in the REPL.
|
300
297
|
def doc
|
301
298
|
@doc ||= case source_type
|
302
299
|
when :c
|
303
300
|
info = pry_doc_info
|
304
301
|
info.docstring if info
|
305
302
|
when :ruby
|
306
|
-
|
303
|
+
if rbx? && !pry_method?
|
304
|
+
get_comment_content(core_doc)
|
305
|
+
elsif pry_method?
|
306
|
+
get_comment_content(doc_for_pry_method)
|
307
|
+
else
|
308
|
+
get_comment_content(@method.comment)
|
309
|
+
end
|
307
310
|
end
|
308
311
|
end
|
309
312
|
|
@@ -313,6 +316,15 @@ class Pry
|
|
313
316
|
source_location.nil? ? :c : :ruby
|
314
317
|
end
|
315
318
|
|
319
|
+
def source_location
|
320
|
+
if @method.source_location && rbx?
|
321
|
+
file, line = @method.source_location
|
322
|
+
[RbxPath.convert_path_to_full(file), line]
|
323
|
+
else
|
324
|
+
@method.source_location
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
316
328
|
# @return [String, nil] The name of the file the method is defined in, or
|
317
329
|
# `nil` if the filename is unavailable.
|
318
330
|
def source_file
|
@@ -422,14 +434,15 @@ class Pry
|
|
422
434
|
end
|
423
435
|
|
424
436
|
# @return [Array<String>] All known aliases for the method.
|
437
|
+
# @note On Ruby 1.8 this method always returns an empty Array for methods
|
438
|
+
# implemented in C.
|
425
439
|
def aliases
|
426
440
|
owner = @method.owner
|
427
441
|
# Avoid using `to_sym` on {Method#name}, which returns a `String`, because
|
428
442
|
# it won't be garbage collected.
|
429
443
|
name = @method.name
|
430
444
|
|
431
|
-
|
432
|
-
alias_list = all_methods_to_compare.combination(2).select do |pair|
|
445
|
+
alias_list = owner.instance_methods.combination(2).select do |pair|
|
433
446
|
pair.include?(name) &&
|
434
447
|
owner.instance_method(pair.first) == owner.instance_method(pair.last)
|
435
448
|
end.flatten
|
@@ -470,10 +483,6 @@ class Pry
|
|
470
483
|
@method.send(method_name, *args, &block)
|
471
484
|
end
|
472
485
|
|
473
|
-
def comment
|
474
|
-
Pry::Code.from_file(source_file).comment_describing(source_line)
|
475
|
-
end
|
476
|
-
|
477
486
|
private
|
478
487
|
|
479
488
|
# @return [YARD::CodeObjects::MethodObject]
|
@@ -483,13 +492,31 @@ class Pry
|
|
483
492
|
Pry::MethodInfo.info_for(@method) or raise CommandError, "Cannot locate this method: #{name}. (source_location returns nil)"
|
484
493
|
else
|
485
494
|
fail_msg = "Cannot locate this method: #{name}."
|
486
|
-
if
|
495
|
+
if mri_18? || mri_19?
|
487
496
|
fail_msg += ' Try `gem-install pry-doc` to get access to Ruby Core documentation.'
|
488
497
|
end
|
489
498
|
raise CommandError, fail_msg
|
490
499
|
end
|
491
500
|
end
|
492
501
|
|
502
|
+
# FIXME: a very similar method to this exists on WrappedModule: extract_doc_for_candidate
|
503
|
+
def doc_for_pry_method
|
504
|
+
_, line_num = source_location
|
505
|
+
|
506
|
+
buffer = ""
|
507
|
+
Pry.line_buffer[0..(line_num - 1)].each do |line|
|
508
|
+
# Add any line that is a valid ruby comment,
|
509
|
+
# but clear as soon as we hit a non comment line.
|
510
|
+
if (line =~ /^\s*#/) || (line =~ /^\s*$/)
|
511
|
+
buffer << line.lstrip
|
512
|
+
else
|
513
|
+
buffer.replace("")
|
514
|
+
end
|
515
|
+
end
|
516
|
+
|
517
|
+
buffer
|
518
|
+
end
|
519
|
+
|
493
520
|
# @param [Class, Module] ancestors The ancestors to investigate
|
494
521
|
# @return [Method] The unwrapped super-method
|
495
522
|
def super_using_ancestors(ancestors, times=1)
|
@@ -520,27 +547,5 @@ class Pry
|
|
520
547
|
|
521
548
|
nil
|
522
549
|
end
|
523
|
-
|
524
|
-
def c_source
|
525
|
-
info = pry_doc_info
|
526
|
-
if info and info.source
|
527
|
-
strip_comments_from_c_code(info.source)
|
528
|
-
end
|
529
|
-
end
|
530
|
-
|
531
|
-
def ruby_source
|
532
|
-
# clone of MethodSource.source_helper that knows to use our
|
533
|
-
# hacked version of source_location for rbx core methods, and
|
534
|
-
# our input buffer for methods defined in (pry)
|
535
|
-
file, line = *source_location
|
536
|
-
raise SourceNotFoundError, "Could not locate source for #{name_with_owner}!" unless file
|
537
|
-
|
538
|
-
begin
|
539
|
-
code = Pry::Code.from_file(file).expression_at(line)
|
540
|
-
rescue SyntaxError => e
|
541
|
-
raise MethodSource::SourceNotFoundError.new(e.message)
|
542
|
-
end
|
543
|
-
strip_leading_whitespace(code)
|
544
|
-
end
|
545
550
|
end
|
546
551
|
end
|