pry 0.8.4pre1-i386-mingw32 → 0.9.0-i386-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG +25 -6
- data/README.markdown +11 -4
- data/Rakefile +15 -19
- data/TODO +28 -2
- data/bin/pry +28 -11
- data/examples/example_basic.rb +2 -4
- data/examples/example_command_override.rb +2 -5
- data/examples/example_commands.rb +1 -4
- data/examples/example_hooks.rb +2 -5
- data/examples/example_image_edit.rb +4 -8
- data/examples/example_input.rb +1 -4
- data/examples/example_input2.rb +1 -4
- data/examples/example_output.rb +1 -4
- data/examples/example_print.rb +2 -5
- data/examples/example_prompt.rb +2 -5
- data/examples/helper.rb +6 -0
- data/lib/pry.rb +59 -3
- data/lib/pry/command_context.rb +10 -9
- data/lib/pry/command_processor.rb +51 -73
- data/lib/pry/command_set.rb +79 -28
- data/lib/pry/commands.rb +9 -123
- data/lib/pry/completion.rb +30 -29
- data/lib/pry/config.rb +100 -0
- data/lib/pry/default_commands/basic.rb +37 -0
- data/lib/pry/default_commands/context.rb +16 -15
- data/lib/pry/default_commands/documentation.rb +73 -54
- data/lib/pry/default_commands/easter_eggs.rb +1 -20
- data/lib/pry/default_commands/gems.rb +31 -40
- data/lib/pry/default_commands/input.rb +223 -15
- data/lib/pry/default_commands/introspection.rb +108 -73
- data/lib/pry/default_commands/ls.rb +25 -11
- data/lib/pry/default_commands/shell.rb +29 -39
- data/lib/pry/extended_commands/experimental.rb +17 -0
- data/lib/pry/extended_commands/user_command_api.rb +22 -0
- data/lib/pry/helpers.rb +1 -0
- data/lib/pry/helpers/base_helpers.rb +15 -104
- data/lib/pry/helpers/command_helpers.rb +96 -59
- data/lib/pry/helpers/text.rb +83 -0
- data/lib/pry/history_array.rb +105 -0
- data/lib/pry/plugins.rb +79 -0
- data/lib/pry/pry_class.rb +102 -114
- data/lib/pry/pry_instance.rb +123 -55
- data/lib/pry/version.rb +1 -1
- data/pry.gemspec +45 -0
- data/test/helper.rb +57 -7
- data/test/test_command_processor.rb +205 -0
- data/test/{test_commandset.rb → test_command_set.rb} +18 -12
- data/test/test_default_commands.rb +59 -0
- data/test/test_default_commands/test_context.rb +64 -0
- data/test/test_default_commands/test_documentation.rb +31 -0
- data/test/test_default_commands/test_gems.rb +14 -0
- data/test/test_default_commands/test_input.rb +327 -0
- data/test/test_default_commands/test_introspection.rb +155 -0
- data/test/test_history_array.rb +65 -0
- data/test/test_pry.rb +548 -313
- metadata +48 -15
- data/lib/pry/hooks.rb +0 -17
- data/lib/pry/print.rb +0 -16
- data/lib/pry/prompts.rb +0 -31
@@ -1,7 +1,17 @@
|
|
1
1
|
class Pry
|
2
2
|
module DefaultCommands
|
3
3
|
|
4
|
-
Ls = Pry::CommandSet.new
|
4
|
+
Ls = Pry::CommandSet.new do
|
5
|
+
|
6
|
+
helpers do
|
7
|
+
def trim_methods(options, visibility)
|
8
|
+
if options[:e]
|
9
|
+
[]
|
10
|
+
else
|
11
|
+
Object.send("#{visibility}_methods")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
5
15
|
|
6
16
|
command "ls", "Show the list of vars and methods in the current scope. Type `ls --help` for more info." do |*args|
|
7
17
|
options = {}
|
@@ -59,10 +69,14 @@ Shows local and instance variables by default.
|
|
59
69
|
options[:j] = true
|
60
70
|
end
|
61
71
|
|
62
|
-
opts.on("-s", "--super", "Include superclass entries (relevant to constant and methods options).") do
|
72
|
+
opts.on("-s", "--super", "Include superclass entries excluding Object (relevant to constant and methods options).") do
|
63
73
|
options[:s] = true
|
64
74
|
end
|
65
75
|
|
76
|
+
opts.on("-e", "--everything", "Include superclass entries including Object (relevant to constant and methods options).") do
|
77
|
+
options[:e] = true
|
78
|
+
end
|
79
|
+
|
66
80
|
opts.on("-a", "--all", "Display all types of entries.") do
|
67
81
|
options[:a] = true
|
68
82
|
end
|
@@ -126,19 +140,19 @@ Shows local and instance variables by default.
|
|
126
140
|
|
127
141
|
info["global variables"] = [Array(target.eval("global_variables")).sort, i += 1] if options[:g] || options[:a]
|
128
142
|
|
129
|
-
info["public methods"] = [Array(target.eval("public_methods(#{options[:s]})")).uniq.sort, i += 1] if (options[:m] && options[:P]) || options[:a]
|
143
|
+
info["public methods"] = [Array(target.eval("public_methods(#{options[:s]})")).uniq.sort - trim_methods(options, :public), i += 1] if (options[:m] && options[:P]) || options[:a]
|
130
144
|
|
131
|
-
info["protected methods"] = [Array(target.eval("protected_methods(#{options[:s]})")).sort, i += 1] if (options[:m] && options[:r]) || options[:a]
|
145
|
+
info["protected methods"] = [Array(target.eval("protected_methods(#{options[:s]})")).sort - trim_methods(options, :protected), i += 1] if (options[:m] && options[:r]) || options[:a]
|
132
146
|
|
133
|
-
info["private methods"] = [Array(target.eval("private_methods(#{options[:s]})")).sort, i += 1] if (options[:m] && options[:p]) || options[:a]
|
147
|
+
info["private methods"] = [Array(target.eval("private_methods(#{options[:s]})")).sort - trim_methods(options, :private), i += 1] if (options[:m] && options[:p]) || options[:a]
|
134
148
|
|
135
149
|
info["just singleton methods"] = [Array(target.eval("methods(#{options[:s]})")).sort, i += 1] if (options[:m] && options[:j]) || options[:a]
|
136
150
|
|
137
|
-
info["public instance methods"] = [Array(target.eval("public_instance_methods(#{options[:s]})")).uniq.sort, i += 1] if target_self.is_a?(Module) && ((options[:M] && options[:P]) || options[:a])
|
151
|
+
info["public instance methods"] = [Array(target.eval("public_instance_methods(#{options[:s]})")).uniq.sort - trim_methods(options, :public), i += 1] if target_self.is_a?(Module) && ((options[:M] && options[:P]) || options[:a])
|
138
152
|
|
139
|
-
info["protected instance methods"] = [Array(target.eval("protected_instance_methods(#{options[:s]})")).uniq.sort, i += 1] if target_self.is_a?(Module) && ((options[:M] && options[:r]) || options[:a])
|
153
|
+
info["protected instance methods"] = [Array(target.eval("protected_instance_methods(#{options[:s]})")).uniq.sort - trim_methods(options, :protected), i += 1] if target_self.is_a?(Module) && ((options[:M] && options[:r]) || options[:a])
|
140
154
|
|
141
|
-
info["private instance methods"] = [Array(target.eval("private_instance_methods(#{options[:s]})")).uniq.sort, i += 1] if target_self.is_a?(Module) && ((options[:M] && options[:p]) || options[:a])
|
155
|
+
info["private instance methods"] = [Array(target.eval("private_instance_methods(#{options[:s]})")).uniq.sort - trim_methods(options, :private), i += 1] if target_self.is_a?(Module) && ((options[:M] && options[:p]) || options[:a])
|
142
156
|
|
143
157
|
# dealing with 1.8/1.9 compatibility issues :/
|
144
158
|
csuper = options[:s]
|
@@ -180,9 +194,9 @@ Shows local and instance variables by default.
|
|
180
194
|
list = list.grep(options[:grep]) if list
|
181
195
|
list.uniq! if list
|
182
196
|
if Pry.color
|
183
|
-
text << CodeRay.scan(
|
197
|
+
text << CodeRay.scan(list.inspect, :ruby).term + "\n"
|
184
198
|
else
|
185
|
-
text <<
|
199
|
+
text << list.inspect + "\n"
|
186
200
|
end
|
187
201
|
if !options[:f]
|
188
202
|
stagger_output(text)
|
@@ -194,6 +208,6 @@ Shows local and instance variables by default.
|
|
194
208
|
end
|
195
209
|
|
196
210
|
|
197
|
-
end
|
198
211
|
end
|
199
212
|
end
|
213
|
+
end
|
@@ -1,10 +1,22 @@
|
|
1
1
|
class Pry
|
2
2
|
module DefaultCommands
|
3
3
|
|
4
|
-
Shell = Pry::CommandSet.new
|
4
|
+
Shell = Pry::CommandSet.new do
|
5
|
+
|
6
|
+
command(/\.(.*)/, "All text following a '.' is forwarded to the shell.", :listing => ".<shell command>") do |cmd|
|
7
|
+
if cmd =~ /^cd\s+(.+)/i
|
8
|
+
dest = $1
|
9
|
+
begin
|
10
|
+
Dir.chdir File.expand_path(dest)
|
11
|
+
rescue Errno::ENOENT
|
12
|
+
output.puts "No such directory: #{dest}"
|
13
|
+
end
|
5
14
|
|
6
|
-
|
7
|
-
|
15
|
+
else
|
16
|
+
if !system(cmd)
|
17
|
+
output.puts "Error: there was a problem executing system command: #{cmd}"
|
18
|
+
end
|
19
|
+
end
|
8
20
|
end
|
9
21
|
|
10
22
|
command "shell-mode", "Toggle shell mode. Bring in pwd prompt and file completion." do
|
@@ -22,50 +34,30 @@ class Pry
|
|
22
34
|
|
23
35
|
alias_command "file-mode", "shell-mode", ""
|
24
36
|
|
25
|
-
|
26
37
|
command "cat", "Show output of file FILE. Type `cat --help` for more information." do |*args|
|
27
|
-
options= {}
|
28
|
-
file_name = nil
|
29
38
|
start_line = 0
|
30
39
|
end_line = -1
|
31
|
-
file_type = nil
|
32
|
-
|
33
|
-
OptionParser.new do |opts|
|
34
|
-
opts.banner = %{Usage: cat [OPTIONS] FILE
|
35
|
-
Cat a file. Defaults to displaying whole file. Syntax highlights file if type is recognized.
|
36
|
-
e.g: cat hello.rb
|
37
|
-
--
|
38
|
-
}
|
39
|
-
opts.on("-l", "--line-numbers", "Show line numbers.") do |line|
|
40
|
-
options[:l] = true
|
41
|
-
end
|
42
40
|
|
43
|
-
|
44
|
-
|
41
|
+
opts = Slop.parse!(args) do |opt|
|
42
|
+
opt.on :s, :start, "Start line (defaults to start of file)Line 1 is the first line.", true, :as => Integer do |line|
|
43
|
+
start_line = line - 1
|
45
44
|
end
|
46
45
|
|
47
|
-
|
48
|
-
end_line = line
|
46
|
+
opt.on :e, :end, "End line (defaults to end of file). Line -1 is the last line", true, :as => Integer do |line|
|
47
|
+
end_line = line - 1
|
49
48
|
end
|
50
49
|
|
51
|
-
|
52
|
-
|
50
|
+
opt.on :l, "line-numbers", "Show line numbers."
|
51
|
+
opt.on :t, :type, "The specific file type for syntax higlighting (e.g ruby, python)", true, :as => Symbol
|
52
|
+
opt.on :f, :flood, "Do not use a pager to view text longer than one screen."
|
53
|
+
opt.on :h, :help, "This message." do
|
54
|
+
output.puts opt
|
53
55
|
end
|
54
|
-
|
55
|
-
opts.on("-f", "--flood", "Do not use a pager to view text longer than one screen.") do
|
56
|
-
options[:f] = true
|
57
|
-
end
|
58
|
-
|
59
|
-
opts.on_tail("-h", "--help", "This message.") do
|
60
|
-
output.puts opts
|
61
|
-
options[:h] = true
|
62
|
-
end
|
63
|
-
end.order(args) do |v|
|
64
|
-
file_name = v
|
65
56
|
end
|
66
57
|
|
67
|
-
next if
|
58
|
+
next if opts.help?
|
68
59
|
|
60
|
+
file_name = args.shift
|
69
61
|
if !file_name
|
70
62
|
output.puts "Must provide a file name."
|
71
63
|
next
|
@@ -74,15 +66,13 @@ e.g: cat hello.rb
|
|
74
66
|
contents, normalized_start_line, _ = read_between_the_lines(file_name, start_line, end_line)
|
75
67
|
|
76
68
|
if Pry.color
|
77
|
-
contents = syntax_highlight_by_file_type_or_specified(contents, file_name,
|
69
|
+
contents = syntax_highlight_by_file_type_or_specified(contents, file_name, opts[:type])
|
78
70
|
end
|
79
71
|
|
80
72
|
set_file_and_dir_locals(file_name)
|
81
|
-
render_output(
|
73
|
+
render_output(opts.flood?, opts.l? ? normalized_start_line + 1 : false, contents)
|
82
74
|
contents
|
83
75
|
end
|
84
|
-
|
85
|
-
|
86
76
|
end
|
87
77
|
|
88
78
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Pry
|
2
|
+
module ExtendedCommands
|
3
|
+
|
4
|
+
Experimental = Pry::CommandSet.new do
|
5
|
+
|
6
|
+
command "reload-method", "Reload the source specifically for a method", :requires_gem => "method_reload" do |meth_name|
|
7
|
+
if (meth = get_method_object(meth_name, target, {})).nil?
|
8
|
+
output.puts "Invalid method name: #{meth_name}."
|
9
|
+
next
|
10
|
+
end
|
11
|
+
|
12
|
+
meth.reload
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class Pry
|
2
|
+
module ExtendedCommands
|
3
|
+
|
4
|
+
UserCommandAPI = Pry::CommandSet.new do
|
5
|
+
|
6
|
+
command "define-command", "Define a command in the session, use same syntax as `command` method for command API" do |arg|
|
7
|
+
next output.puts("Provide an arg!") if arg.nil?
|
8
|
+
|
9
|
+
prime_string = "command #{arg_string}\n"
|
10
|
+
command_string = Pry.active_instance.r(target, prime_string)
|
11
|
+
|
12
|
+
eval_string.replace <<-HERE
|
13
|
+
_pry_.commands.instance_eval do
|
14
|
+
#{command_string}
|
15
|
+
end
|
16
|
+
HERE
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/pry/helpers.rb
CHANGED
@@ -14,18 +14,16 @@ class Pry
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
ensure
|
23
|
-
Pry.color = old_color_state
|
17
|
+
def find_command(name)
|
18
|
+
command_match = commands.find { |_, command| command.options[:listing] == name }
|
19
|
+
|
20
|
+
return command_match.last if command_match
|
21
|
+
nil
|
24
22
|
end
|
25
23
|
|
26
24
|
def gem_installed?(gem_name)
|
27
25
|
require 'rubygems'
|
28
|
-
|
26
|
+
Gem::Specification.respond_to?(:find_all_by_name) ? !Gem::Specification.find_all_by_name(gem_name).empty? : Gem.source_index.find_name(gem_name).first
|
29
27
|
end
|
30
28
|
|
31
29
|
def command_dependencies_met?(options)
|
@@ -47,8 +45,10 @@ class Pry
|
|
47
45
|
gems_needed = Array(options[:requires_gem])
|
48
46
|
gems_not_installed = gems_needed.select { |g| !gem_installed?(g) }
|
49
47
|
proc do
|
50
|
-
output.puts "\
|
48
|
+
output.puts "\nThe command '#{name}' requires the following gems to be installed: #{(gems_needed.join(", "))}"
|
49
|
+
output.puts "-"
|
51
50
|
output.puts "Command not available due to dependency on gems: `#{gems_not_installed.join(", ")}` not being met."
|
51
|
+
output.puts "-"
|
52
52
|
output.puts "Type `install #{name}` to install the required gems and activate this command."
|
53
53
|
end
|
54
54
|
end
|
@@ -63,101 +63,12 @@ class Pry
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
# ANSI color codes:
|
72
|
-
# \033 => escape
|
73
|
-
# 30 => color base
|
74
|
-
# 1 => bright
|
75
|
-
# 0 => normal
|
76
|
-
#
|
77
|
-
|
78
|
-
COLORS = {
|
79
|
-
"black" => 0,
|
80
|
-
"red" => 1,
|
81
|
-
"green" => 2,
|
82
|
-
"yellow" => 3,
|
83
|
-
"blue" => 4,
|
84
|
-
"purple" => 5,
|
85
|
-
"magenta" => 5,
|
86
|
-
"cyan" => 6,
|
87
|
-
"white" => 7
|
88
|
-
}
|
89
|
-
|
90
|
-
COLORS.each do |color, i|
|
91
|
-
define_method color do |str|
|
92
|
-
Pry.color ? "\033[0;#{30+i}m#{str}\033[0m" : str
|
93
|
-
end
|
94
|
-
|
95
|
-
define_method "bright_#{color}" do |str|
|
96
|
-
Pry.color ? "\033[1;#{30+i}m#{str}\033[0m" : str
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
alias_method :grey, :bright_black
|
101
|
-
alias_method :gray, :bright_black
|
102
|
-
|
103
|
-
require 'set'
|
104
|
-
VALID_COLORS = Set.new(
|
105
|
-
COLORS.keys +
|
106
|
-
COLORS.keys.map{|k| "bright_#{k}" } +
|
107
|
-
["grey", "gray"]
|
108
|
-
)
|
109
|
-
|
110
|
-
def bold(text)
|
111
|
-
Pry.color ? "\e[1m#{text}\e[0m" : text
|
112
|
-
end
|
113
|
-
|
114
|
-
#
|
115
|
-
# Colorize a string that has "color tags".
|
116
|
-
#
|
117
|
-
# Examples:
|
118
|
-
# puts colorize("<light_green><magenta>*</magenta> Hey mom! I am <light_blue>SO</light_blue> colored right now.</light_green>")
|
119
|
-
#
|
120
|
-
def colorize(string)
|
121
|
-
stack = []
|
122
|
-
|
123
|
-
# split the string into tags and literal strings
|
124
|
-
tokens = string.split(/(<\/?[\w\d_]+>)/)
|
125
|
-
tokens.delete_if { |token| token.size == 0 }
|
126
|
-
|
127
|
-
result = ""
|
128
|
-
|
129
|
-
tokens.each do |token|
|
130
|
-
|
131
|
-
# token is an opening tag!
|
132
|
-
|
133
|
-
if /<([\w\d_]+)>/ =~ token and VALID_COLORS.include?($1) #valid_tag?($1)
|
134
|
-
stack.push $1
|
135
|
-
|
136
|
-
# token is a closing tag!
|
137
|
-
|
138
|
-
elsif /<\/([\w\d_]+)>/ =~ token and VALID_COLORS.include?($1) # valid_tag?($1)
|
139
|
-
|
140
|
-
# if this color is on the stack somwehere...
|
141
|
-
if pos = stack.rindex($1)
|
142
|
-
# close the tag by removing it from the stack
|
143
|
-
stack.delete_at pos
|
144
|
-
else
|
145
|
-
raise "Error: tried to close an unopened color tag -- #{token}"
|
146
|
-
end
|
147
|
-
|
148
|
-
# token is a literal string!
|
149
|
-
|
150
|
-
else
|
151
|
-
|
152
|
-
color = (stack.last || "white")
|
153
|
-
#color = BBS_COLOR_TABLE[color.to_i] if color =~ /^\d+$/
|
154
|
-
result << send(color, token) # colorize the result
|
155
|
-
|
156
|
-
end
|
157
|
-
|
66
|
+
def colorize_code(code)
|
67
|
+
if Pry.color
|
68
|
+
CodeRay.scan(code, :ruby).term
|
69
|
+
else
|
70
|
+
code
|
158
71
|
end
|
159
|
-
|
160
|
-
result
|
161
72
|
end
|
162
73
|
|
163
74
|
def highlight(string, regexp, highlight_color=:bright_yellow)
|
@@ -190,7 +101,7 @@ class Pry
|
|
190
101
|
# Try to use `less` for paging, if it fails then use
|
191
102
|
# simple_pager. Also do not page if Pry.pager is falsey
|
192
103
|
# FIXME! Another JRuby hack
|
193
|
-
def stagger_output(text)
|
104
|
+
def stagger_output(text, output=output())
|
194
105
|
if text.lines.count < page_size || !Pry.pager
|
195
106
|
output.puts text
|
196
107
|
return
|
@@ -5,15 +5,6 @@ class Pry
|
|
5
5
|
|
6
6
|
module_function
|
7
7
|
|
8
|
-
def try_to_load_pry_doc
|
9
|
-
|
10
|
-
# YARD crashes on rbx, so do not require it
|
11
|
-
if !Object.const_defined?(:RUBY_ENGINE) || RUBY_ENGINE !~ /rbx/
|
12
|
-
require "pry-doc"
|
13
|
-
end
|
14
|
-
rescue LoadError
|
15
|
-
end
|
16
|
-
|
17
8
|
def meth_name_from_binding(b)
|
18
9
|
meth_name = b.eval('__method__')
|
19
10
|
if [:__script__, nil, :__binding__, :__binding_impl__].include?(meth_name)
|
@@ -23,29 +14,16 @@ class Pry
|
|
23
14
|
end
|
24
15
|
end
|
25
16
|
|
26
|
-
def add_line_numbers(lines, start_line)
|
27
|
-
line_array = lines.each_line.to_a
|
28
|
-
line_array.each_with_index.map do |line, idx|
|
29
|
-
adjusted_index = idx + start_line
|
30
|
-
if Pry.color
|
31
|
-
cindex = CodeRay.scan("#{adjusted_index}", :ruby).term
|
32
|
-
"#{cindex}: #{line}"
|
33
|
-
else
|
34
|
-
"#{idx}: #{line}"
|
35
|
-
end
|
36
|
-
end.join
|
37
|
-
end
|
38
|
-
|
39
17
|
# if start_line is not false then add line numbers starting with start_line
|
40
|
-
def render_output(should_flood, start_line,
|
18
|
+
def render_output(should_flood, start_line, text)
|
41
19
|
if start_line
|
42
|
-
|
20
|
+
text = Pry::Helpers::Text.with_line_numbers text, start_line
|
43
21
|
end
|
44
22
|
|
45
23
|
if should_flood
|
46
|
-
output.puts
|
24
|
+
output.puts text
|
47
25
|
else
|
48
|
-
stagger_output(
|
26
|
+
stagger_output(text)
|
49
27
|
end
|
50
28
|
end
|
51
29
|
|
@@ -55,31 +33,74 @@ class Pry
|
|
55
33
|
end
|
56
34
|
|
57
35
|
def check_for_dynamically_defined_method(meth)
|
58
|
-
|
36
|
+
file, _ = meth.source_location
|
37
|
+
if file =~ /(\(.*\))|<.*>/ && file != Pry.eval_path
|
59
38
|
raise "Cannot retrieve source for dynamically defined method."
|
60
39
|
end
|
61
40
|
end
|
62
41
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
42
|
+
########### RBX HELPERS #############
|
43
|
+
def rbx_core?(meth)
|
44
|
+
defined?(RUBY_ENGINE) &&
|
45
|
+
RUBY_ENGINE =~ /rbx/ &&
|
46
|
+
meth.source_location &&
|
47
|
+
meth.source_location.first.start_with?("kernel")
|
48
|
+
end
|
49
|
+
|
50
|
+
def rvm_ruby?(path)
|
51
|
+
!!(path =~ /\.rvm/)
|
52
|
+
end
|
53
|
+
|
54
|
+
def rbx_core_code_for(meth)
|
55
|
+
rbx_core_code_or_doc_for(meth, :code)
|
56
|
+
end
|
57
|
+
|
58
|
+
def rbx_core_doc_for(meth)
|
59
|
+
rbx_core_code_or_doc_for(meth, :doc)
|
60
|
+
end
|
61
|
+
|
62
|
+
def rbx_core_code_or_doc_for(meth, code_or_doc)
|
63
|
+
path_line = rbx_core_path_line_for(meth)
|
64
|
+
|
65
|
+
case code_or_doc
|
66
|
+
when :code
|
67
|
+
MethodSource.source_helper(path_line)
|
68
|
+
when :doc
|
69
|
+
MethodSource.comment_helper(path_line)
|
67
70
|
end
|
68
71
|
end
|
69
72
|
|
70
|
-
def
|
71
|
-
|
73
|
+
def rbx_core_path_line_for(meth)
|
74
|
+
if rvm_ruby?(Rubinius::BIN_PATH)
|
75
|
+
rvm_rbx_core_path_line_for(meth)
|
76
|
+
else
|
77
|
+
std_rbx_core_path_line_for(meth)
|
78
|
+
end
|
72
79
|
end
|
73
80
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
+
def std_rbx_core_path_line_for(meth)
|
82
|
+
file_name = File.join(Rubinius::BIN_PATH, "..", meth.source_location.first)
|
83
|
+
raise "Cannot find rbx core source" if !File.exists?(file_name)
|
84
|
+
|
85
|
+
start_line = meth.source_location.last
|
86
|
+
|
87
|
+
[file_name, start_line]
|
81
88
|
end
|
82
89
|
|
90
|
+
def rvm_rbx_core_path_line_for(meth)
|
91
|
+
ruby_name = File.dirname(Rubinius::BIN_PATH).split("/").last
|
92
|
+
source_path = File.join(File.dirname(File.dirname(File.dirname(Rubinius::BIN_PATH))), "src", ruby_name)
|
93
|
+
|
94
|
+
file_name = File.join(source_path, meth.source_location.first)
|
95
|
+
raise "Cannot find rbx core source" if !File.exists?(file_name)
|
96
|
+
|
97
|
+
start_line = meth.source_location.last
|
98
|
+
|
99
|
+
[file_name, start_line]
|
100
|
+
end
|
101
|
+
|
102
|
+
######### END RBX HELPERS ###############
|
103
|
+
|
83
104
|
def code_and_code_type_for(meth)
|
84
105
|
case code_type = code_type_for(meth)
|
85
106
|
when nil
|
@@ -88,8 +109,18 @@ class Pry
|
|
88
109
|
code = Pry::MethodInfo.info_for(meth).source
|
89
110
|
code = strip_comments_from_c_code(code)
|
90
111
|
when :ruby
|
91
|
-
|
92
|
-
|
112
|
+
if meth.source_location.first == Pry.eval_path
|
113
|
+
start_line = meth.source_location.last
|
114
|
+
p = Pry.new(:input => StringIO.new(Pry.line_buffer[start_line..-1].join)).r(target)
|
115
|
+
code = strip_leading_whitespace(p)
|
116
|
+
else
|
117
|
+
if rbx_core?(meth)
|
118
|
+
code = strip_leading_whitespace(rbx_core_code_for(meth))
|
119
|
+
else
|
120
|
+
code = strip_leading_whitespace(meth.source)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
set_file_and_dir_locals(path_line_for(meth).first)
|
93
124
|
end
|
94
125
|
|
95
126
|
[code, code_type]
|
@@ -102,9 +133,12 @@ class Pry
|
|
102
133
|
when :c
|
103
134
|
doc = Pry::MethodInfo.info_for(meth).docstring
|
104
135
|
when :ruby
|
105
|
-
|
106
|
-
|
107
|
-
|
136
|
+
if rbx_core?(meth)
|
137
|
+
doc = strip_leading_hash_and_whitespace_from_ruby_comments(rbx_core_doc_for(meth))
|
138
|
+
else
|
139
|
+
doc = strip_leading_hash_and_whitespace_from_ruby_comments(meth.comment)
|
140
|
+
end
|
141
|
+
set_file_and_dir_locals(path_line_for(meth).first)
|
108
142
|
end
|
109
143
|
|
110
144
|
[doc, code_type]
|
@@ -144,15 +178,23 @@ class Pry
|
|
144
178
|
end
|
145
179
|
end
|
146
180
|
|
181
|
+
def path_line_for(meth)
|
182
|
+
if rbx_core?(meth)
|
183
|
+
rbx_core_path_line_for(meth)
|
184
|
+
else
|
185
|
+
meth.source_location
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
147
189
|
def make_header(meth, code_type, content)
|
148
|
-
num_lines = "Number of lines: #{bold(content.each_line.count.to_s)}"
|
190
|
+
num_lines = "Number of lines: #{Pry::Helpers::Text.bold(content.each_line.count.to_s)}"
|
149
191
|
case code_type
|
150
192
|
when :ruby
|
151
|
-
file, line = meth
|
152
|
-
"\n#{bold('From:')} #{file} @ line #{line}:\n#{num_lines}\n\n"
|
193
|
+
file, line = path_line_for(meth)
|
194
|
+
"\n#{Pry::Helpers::Text.bold('From:')} #{file} @ line #{line}:\n#{num_lines}\n\n"
|
153
195
|
else
|
154
196
|
file = Pry::MethodInfo.info_for(meth).file
|
155
|
-
"\n#{bold('From:')} #{file} in Ruby Core (C Method):\n#{num_lines}\n\n"
|
197
|
+
"\n#{Pry::Helpers::Text.bold('From:')} #{file} in Ruby Core (C Method):\n#{num_lines}\n\n"
|
156
198
|
end
|
157
199
|
end
|
158
200
|
|
@@ -161,7 +203,7 @@ class Pry
|
|
161
203
|
end
|
162
204
|
|
163
205
|
def should_use_pry_doc?(meth)
|
164
|
-
Pry.has_pry_doc && is_a_c_method?(meth)
|
206
|
+
Pry.config.has_pry_doc && is_a_c_method?(meth)
|
165
207
|
end
|
166
208
|
|
167
209
|
def code_type_for(meth)
|
@@ -232,16 +274,11 @@ class Pry
|
|
232
274
|
normalized_line_number(end_line, lines_array.size)]
|
233
275
|
end
|
234
276
|
|
235
|
-
# documentation related helpers
|
236
|
-
def strip_color_codes(str)
|
237
|
-
str.gsub(/\e\[.*?(\d)+m/, '')
|
238
|
-
end
|
239
|
-
|
240
277
|
def process_rdoc(comment, code_type)
|
241
278
|
comment = comment.dup
|
242
279
|
comment.gsub(/<code>(?:\s*\n)?(.*?)\s*<\/code>/m) { Pry.color ? CodeRay.scan($1, code_type).term : $1 }.
|
243
|
-
gsub(/<em>(?:\s*\n)?(.*?)\s*<\/em>/m) { Pry.color ? "\e[
|
244
|
-
gsub(/<i>(?:\s*\n)?(.*?)\s*<\/i>/m) { Pry.color ? "\e[
|
280
|
+
gsub(/<em>(?:\s*\n)?(.*?)\s*<\/em>/m) { Pry.color ? "\e[1m#{$1}\e[0m": $1 }.
|
281
|
+
gsub(/<i>(?:\s*\n)?(.*?)\s*<\/i>/m) { Pry.color ? "\e[1m#{$1}\e[0m" : $1 }.
|
245
282
|
gsub(/\B\+(\w*?)\+\B/) { Pry.color ? "\e[32m#{$1}\e[0m": $1 }.
|
246
283
|
gsub(/((?:^[ \t]+.+(?:\n+|\Z))+)/) { Pry.color ? CodeRay.scan($1, code_type).term : $1 }.
|
247
284
|
gsub(/`(?:\s*\n)?(.*?)\s*`/) { Pry.color ? CodeRay.scan($1, code_type).term : $1 }
|
@@ -251,7 +288,7 @@ class Pry
|
|
251
288
|
in_tag_block = nil
|
252
289
|
output = comment.lines.map do |v|
|
253
290
|
if in_tag_block && v !~ /^\S/
|
254
|
-
|
291
|
+
Pry::Helpers::Text.strip_color Pry::Helpers::Text.strip_color(v)
|
255
292
|
elsif in_tag_block
|
256
293
|
in_tag_block = false
|
257
294
|
v
|
@@ -288,7 +325,7 @@ class Pry
|
|
288
325
|
end
|
289
326
|
|
290
327
|
def strip_comments_from_c_code(code)
|
291
|
-
code.sub
|
328
|
+
code.sub(/\A\s*\/\*.*?\*\/\s*/m, '')
|
292
329
|
end
|
293
330
|
|
294
331
|
def prompt(message, options="Yn")
|