pry 0.4.8 → 0.5.0pre2
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.
- data/lib/pry/commands.rb +268 -49
- data/lib/pry/hooks.rb +2 -2
- data/lib/pry/prompts.rb +6 -4
- data/lib/pry/pry_class.rb +30 -0
- data/lib/pry/pry_instance.rb +10 -22
- data/lib/pry/version.rb +1 -1
- data/test/test.rb +11 -11
- metadata +40 -74
data/lib/pry/commands.rb
CHANGED
@@ -1,13 +1,24 @@
|
|
1
1
|
direc = File.dirname(__FILE__)
|
2
2
|
require "#{direc}/command_base"
|
3
|
+
require "optparse"
|
3
4
|
|
4
5
|
class Pry
|
5
6
|
|
6
7
|
# Default commands used by Pry.
|
7
8
|
class Commands < CommandBase
|
9
|
+
|
10
|
+
# We make this a lambda to avoid documenting it
|
11
|
+
meth_name_from_binding = lambda do |b|
|
12
|
+
meth_name = b.eval('__method__')
|
13
|
+
if [nil, :__binding__, :__binding_impl__].include?(meth_name)
|
14
|
+
nil
|
15
|
+
else
|
16
|
+
meth_name
|
17
|
+
end
|
18
|
+
end
|
8
19
|
|
9
|
-
command "!", "
|
10
|
-
output.puts "
|
20
|
+
command "!", "Clear the input buffer. Useful if the parsing process goes wrong." do
|
21
|
+
output.puts "Input buffer cleared!"
|
11
22
|
opts[:eval_string].clear
|
12
23
|
end
|
13
24
|
|
@@ -15,10 +26,12 @@ class Pry
|
|
15
26
|
Pry.start(target)
|
16
27
|
end
|
17
28
|
|
18
|
-
command
|
29
|
+
command "exit-program", "End the current program. Aliases: quit-program" do
|
19
30
|
exit
|
20
31
|
end
|
21
32
|
|
33
|
+
alias_command "quit-program", "exit-program", ""
|
34
|
+
|
22
35
|
command "nesting", "Show nesting information." do
|
23
36
|
out = output
|
24
37
|
nesting = opts[:nesting]
|
@@ -27,9 +40,9 @@ class Pry
|
|
27
40
|
out.puts "--"
|
28
41
|
nesting.each do |level, obj|
|
29
42
|
if level == 0
|
30
|
-
out.puts "#{level}. #{Pry.
|
43
|
+
out.puts "#{level}. #{Pry.view_clip(obj)} (Pry top level)"
|
31
44
|
else
|
32
|
-
out.puts "#{level}. #{Pry.
|
45
|
+
out.puts "#{level}. #{Pry.view_clip(obj)}"
|
33
46
|
end
|
34
47
|
end
|
35
48
|
end
|
@@ -40,71 +53,282 @@ class Pry
|
|
40
53
|
|
41
54
|
out.puts "Status:"
|
42
55
|
out.puts "--"
|
43
|
-
out.puts "Receiver: #{Pry.
|
56
|
+
out.puts "Receiver: #{Pry.view_clip(target.eval('self'))}"
|
44
57
|
out.puts "Nesting level: #{nesting.level}"
|
45
|
-
out.puts "
|
58
|
+
out.puts "Pry version: #{Pry::VERSION}"
|
59
|
+
out.puts "Ruby version: #{RUBY_VERSION}"
|
60
|
+
|
61
|
+
mn = meth_name_from_binding.call(target)
|
62
|
+
out.puts "Current method: #{mn ? mn : "N/A"}"
|
46
63
|
out.puts "Pry instance: #{Pry.active_instance}"
|
47
64
|
out.puts "Last result: #{Pry.view(Pry.last_result)}"
|
48
65
|
end
|
49
66
|
|
50
|
-
command "
|
67
|
+
command "version", "Show Pry version." do
|
68
|
+
output.puts "Pry version: #{Pry::VERSION}"
|
69
|
+
end
|
70
|
+
|
71
|
+
command "exit-all", "End all nested Pry sessions." do
|
51
72
|
throw(:breakout, 0)
|
52
73
|
end
|
53
74
|
|
54
|
-
command "ls", "Show the list of vars in the current scope.
|
55
|
-
|
75
|
+
command "ls", "Show the list of vars in the current scope. Type `ls --help` for more info." do |*args|
|
76
|
+
options = {}
|
77
|
+
|
78
|
+
# Set target local to the default -- note that we can set a different target for
|
79
|
+
# ls if we like: e.g ls my_var
|
80
|
+
target = target()
|
81
|
+
|
82
|
+
OptionParser.new do |opts|
|
83
|
+
opts.banner = %{Usage: ls [OPTIONS] [VAR]\n\
|
84
|
+
List information about VAR (the current context by default).
|
85
|
+
Always shows local and instance variables by default; use -r to restrict to specific types.
|
86
|
+
--
|
87
|
+
}
|
88
|
+
|
89
|
+
opts.on("-g", "--globals", "Display global variables.") do |g|
|
90
|
+
options[:g] = true
|
91
|
+
end
|
92
|
+
|
93
|
+
opts.on("-c", "--constants", "Display constants.") do |c|
|
94
|
+
options[:c] = true
|
95
|
+
end
|
96
|
+
|
97
|
+
opts.on("-l", "--locals", "Display locals.") do |c|
|
98
|
+
options[:l] = true
|
99
|
+
end
|
100
|
+
|
101
|
+
opts.on("-i", "--ivars", "Display instance variables.") do |c|
|
102
|
+
options[:i] = true
|
103
|
+
end
|
104
|
+
|
105
|
+
opts.on("-k", "--class-vars", "Display class variables.") do |c|
|
106
|
+
options[:k] = true
|
107
|
+
end
|
108
|
+
|
109
|
+
opts.on("-m", "--methods", "Display methods.") do |c|
|
110
|
+
options[:m] = true
|
111
|
+
end
|
112
|
+
|
113
|
+
opts.on("-M", "--instance-methods", "Display instance methods (only relevant to classes and modules).") do |c|
|
114
|
+
options[:M] = true
|
115
|
+
end
|
116
|
+
|
117
|
+
opts.on("-s", "--super", "Include superclass entries (relevant to constant and methods options).") do |c|
|
118
|
+
options[:s] = true
|
119
|
+
end
|
120
|
+
|
121
|
+
opts.on("-r", "--restrict", "Restrict to specified types.") do |c|
|
122
|
+
options[:r] = true
|
123
|
+
end
|
124
|
+
|
125
|
+
opts.on("-a", "--all", "Display all types of entries.") do |a|
|
126
|
+
options[:a] = true
|
127
|
+
end
|
128
|
+
|
129
|
+
opts.on("-v", "--verbose", "Verbose ouput.") do |c|
|
130
|
+
options[:v] = true
|
131
|
+
end
|
132
|
+
|
133
|
+
opts.on_tail("-h", "--help", "Show this message.") do
|
134
|
+
output.puts opts
|
135
|
+
options[:h] = true
|
136
|
+
end
|
137
|
+
end.order(args) do |new_target|
|
138
|
+
target = Pry.binding_for(target.eval("#{new_target}")) if !options[:h]
|
139
|
+
end
|
140
|
+
|
141
|
+
# exit if we've displayed help
|
142
|
+
next if options[:h]
|
143
|
+
|
144
|
+
info = {}
|
56
145
|
target_self = target.eval('self')
|
57
146
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
147
|
+
# ensure we have a real boolean and not a `nil` (important when
|
148
|
+
# interpolating in the string)
|
149
|
+
options[:s] = !!options[:s]
|
150
|
+
|
151
|
+
# Numbers (e.g 0, 1, 2) are for ordering the hash values in Ruby
|
152
|
+
# 1.8
|
153
|
+
i = -1
|
154
|
+
info["local variables"] = Array(target.eval("local_variables")).sort, i += 1 if !options[:r] || options[:l] || options[:a]
|
155
|
+
info["instance variables"] = Array(target.eval("instance_variables")).sort, i += 1 if !options[:r] || options[:i] || options[:a]
|
156
|
+
info["class variables"] = (target_self.is_a?(Module) ? Array(target.eval("class_variables")).sort : Array(target.eval("self.class.class_variables")).sort), i += 1 if !options[:r] || options[:k] || options[:a]
|
157
|
+
|
158
|
+
info["global variables"] = Array(target.eval("global_variables")).sort, i += 1 if options[:g] || options[:a]
|
159
|
+
|
160
|
+
info["methods"] = Array(target.eval("methods(#{options[:s]}) + public_methods(#{options[:s]}) +\
|
161
|
+
protected_methods(#{options[:s]}) +\
|
162
|
+
private_methods(#{options[:s]})")).uniq.sort, i += 1 if options[:m] || options[:a]
|
163
|
+
|
164
|
+
info["instance methods"] = Array(target.eval("instance_methods(#{options[:s]}) +\
|
165
|
+
public_instance_methods(#{options[:s]}) +\
|
166
|
+
protected_instance_methods(#{options[:s]}) +\
|
167
|
+
private_instance_methods(#{options[:s]})")).uniq.sort, i += 1 if target_self.is_a?(Module) && (options[:M] || options[:a])
|
168
|
+
|
169
|
+
# dealing with 1.8/1.9 compatibility issues :/
|
170
|
+
csuper = options[:s]
|
171
|
+
if Module.method(:constants).arity == 0
|
172
|
+
csuper = nil
|
173
|
+
end
|
174
|
+
|
175
|
+
info["constants"] = Array(target_self.is_a?(Module) ? target.eval("constants(#{csuper})") :
|
176
|
+
target.eval("self.class.constants(#{csuper})")).uniq.sort, i += 1 if options[:c] || options[:a]
|
177
|
+
|
178
|
+
# verbose output?
|
179
|
+
if options[:v]
|
180
|
+
|
181
|
+
# verbose
|
182
|
+
info.each.sort_by { |k, v| v.last }.each do |k, v|
|
183
|
+
if !v.first.empty?
|
184
|
+
output.puts "#{k}:\n--"
|
185
|
+
output.puts Pry.view(v.first)
|
186
|
+
output.puts
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
# plain
|
62
191
|
else
|
63
|
-
|
64
|
-
output.puts "#{Pry.view(target.eval("local_variables + instance_variables + #{c}"))}"
|
192
|
+
output.puts Pry.view(info.values.sort_by { |v| v.last }.map { |v| v.first }.inject(&:+))
|
65
193
|
end
|
66
194
|
end
|
67
195
|
|
68
|
-
command "cat", "Show output of
|
69
|
-
|
70
|
-
|
196
|
+
command "cat", "Show output of VAR.inspect. Aliases: inspect" do |obj|
|
197
|
+
if !obj
|
198
|
+
output.puts "Must provide an object to inspect."
|
199
|
+
next
|
200
|
+
end
|
201
|
+
|
202
|
+
output.puts target.eval("#{obj}.inspect")
|
71
203
|
end
|
204
|
+
|
205
|
+
alias_command "inspect", "cat", ""
|
72
206
|
|
73
|
-
command "cd", "Start a Pry session on
|
207
|
+
command "cd", "Start a Pry session on VAR (use `cd ..` to go back)" do |obj|
|
208
|
+
if !obj
|
209
|
+
output.puts "Must provide an object."
|
210
|
+
next
|
211
|
+
end
|
212
|
+
|
74
213
|
throw(:breakout, opts[:nesting].level) if obj == ".."
|
75
214
|
target.eval("#{obj}.pry")
|
76
215
|
end
|
77
216
|
|
78
|
-
command "
|
79
|
-
|
80
|
-
|
81
|
-
|
217
|
+
command "show-doc", "Show the comments above METH. Type `show-doc --help` for more info." do |*args|
|
218
|
+
options = {}
|
219
|
+
meth_name = nil
|
220
|
+
|
221
|
+
OptionParser.new do |opts|
|
222
|
+
opts.banner = %{Usage: show-doc [OPTIONS] [METH]
|
223
|
+
Show the comments above method METH. Shows _method_ comments (rather than instance methods) by default.
|
224
|
+
e.g show-doc hello_method
|
225
|
+
--
|
226
|
+
}
|
227
|
+
opts.on("-M", "--instance-methods", "Operate on instance methods instead.") do |m|
|
228
|
+
options[:M] = true
|
229
|
+
end
|
82
230
|
|
83
|
-
|
84
|
-
|
231
|
+
opts.on_tail("-h", "--help", "This message.") do |h|
|
232
|
+
output.puts opts
|
233
|
+
options[:h] = true
|
234
|
+
end
|
235
|
+
end.order(args) do |v|
|
236
|
+
meth_name = v
|
237
|
+
end
|
238
|
+
|
239
|
+
next if options[:h]
|
240
|
+
|
241
|
+
if !meth_name
|
242
|
+
output.puts "You need to specify a method. Type `show-doc --help` for help"
|
243
|
+
next
|
244
|
+
end
|
245
|
+
|
246
|
+
begin
|
247
|
+
if options[:M]
|
248
|
+
meth = target.eval("instance_method(:#{meth_name})")
|
249
|
+
else
|
250
|
+
meth = target.eval("method(:#{meth_name})")
|
251
|
+
end
|
252
|
+
rescue
|
253
|
+
output.puts "Invalid method name: #{meth_name}. Type `show-doc --help` for help"
|
254
|
+
next
|
255
|
+
end
|
256
|
+
|
257
|
+
doc = meth.comment
|
258
|
+
file, line = meth.source_location
|
259
|
+
output.puts "From #{file} @ line ~#{line}:"
|
85
260
|
output.puts doc
|
86
261
|
end
|
87
262
|
|
88
|
-
command "
|
89
|
-
|
90
|
-
meth_name =
|
263
|
+
command "show-method", "Show the source for METH. Type `show-method --help` for more info." do |*args|
|
264
|
+
options = {}
|
265
|
+
meth_name = nil
|
266
|
+
|
267
|
+
OptionParser.new do |opts|
|
268
|
+
opts.banner = %{Usage: show-method [OPTIONS] [METH]
|
269
|
+
Show the source for method METH. Shows _method_ source (rather than instance methods) by default.
|
270
|
+
e.g: show-method hello_method
|
271
|
+
--
|
272
|
+
}
|
273
|
+
opts.on("-M", "--instance-methods", "Operate on instance methods instead.") do |m|
|
274
|
+
options[:M] = true
|
275
|
+
end
|
91
276
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
277
|
+
opts.on_tail("-h", "--help", "This message.") do |h|
|
278
|
+
output.puts opts
|
279
|
+
options[:h] = true
|
280
|
+
end
|
281
|
+
end.order(args) do |v|
|
282
|
+
meth_name = v
|
283
|
+
end
|
284
|
+
|
285
|
+
next if options[:h]
|
286
|
+
|
287
|
+
# If no method name is given then use current method, if it exists
|
288
|
+
meth_name = meth_name_from_binding.call(target) if !meth_name
|
289
|
+
|
290
|
+
if !meth_name
|
291
|
+
output.puts "You need to specify a method. Type `show-method --help` for help"
|
292
|
+
next
|
293
|
+
end
|
294
|
+
|
295
|
+
begin
|
296
|
+
if options[:M]
|
297
|
+
meth = target.eval("instance_method(:#{meth_name})")
|
298
|
+
else
|
299
|
+
meth = target.eval("method(:#{meth_name})")
|
300
|
+
end
|
301
|
+
rescue
|
302
|
+
output.puts "Invalid method name: #{meth_name}. Type `show-method --help` for help"
|
97
303
|
next
|
98
304
|
end
|
99
|
-
output.puts "Error: Not in a method."
|
100
|
-
end
|
101
305
|
|
102
|
-
|
103
|
-
|
306
|
+
code = meth.source
|
307
|
+
file, line = meth.source_location
|
308
|
+
output.puts "From #{file} @ line #{line}:"
|
104
309
|
output.puts code
|
105
310
|
end
|
106
|
-
|
107
|
-
command "
|
311
|
+
|
312
|
+
command "show-command", "Show sourcecode for a Pry command, e.g: show-command ls" do |command_name|
|
313
|
+
cmds = Pry.active_instance.commands.commands
|
314
|
+
|
315
|
+
if !command_name
|
316
|
+
output.puts "You must provide a command name."
|
317
|
+
next
|
318
|
+
end
|
319
|
+
|
320
|
+
if cmds[command_name]
|
321
|
+
meth = cmds[command_name][:action]
|
322
|
+
code = meth.source
|
323
|
+
file, line = meth.source_location
|
324
|
+
output.puts "From #{file} @ line #{line}:"
|
325
|
+
output.puts code
|
326
|
+
else
|
327
|
+
output.puts "No such command: #{command_name}."
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
command "jump-to", "Jump to a Pry session further up the stack, exiting all sessions below." do |break_level|
|
108
332
|
break_level = break_level.to_i
|
109
333
|
nesting = opts[:nesting]
|
110
334
|
|
@@ -119,16 +343,11 @@ class Pry
|
|
119
343
|
end
|
120
344
|
end
|
121
345
|
|
122
|
-
command "
|
123
|
-
output.puts "#{Pry.view(target.eval('(public_methods(false) + private_methods(false) + protected_methods(false)).sort'))}"
|
124
|
-
end
|
125
|
-
|
126
|
-
command "ls_imethods", "List all instance methods defined on class of receiver." do
|
127
|
-
output.puts "#{Pry.view(target.eval('(public_instance_methods(false) + private_instance_methods(false) + protected_instance_methods(false)).sort'))}"
|
128
|
-
end
|
129
|
-
|
130
|
-
command ["exit", "quit", "back"], "End the current Pry session." do
|
346
|
+
command "exit", "End the current Pry session. Aliases: quit, back" do
|
131
347
|
throw(:breakout, opts[:nesting].level)
|
132
348
|
end
|
349
|
+
|
350
|
+
alias_command "quit", "exit", ""
|
351
|
+
alias_command "back", "exit", ""
|
133
352
|
end
|
134
353
|
end
|
data/lib/pry/hooks.rb
CHANGED
@@ -2,7 +2,7 @@ class Pry
|
|
2
2
|
|
3
3
|
# The default hooks - display messages when beginning and ending Pry sessions.
|
4
4
|
DEFAULT_HOOKS = {
|
5
|
-
:before_session => proc { |out, obj| out.puts "Beginning Pry session for #{Pry.
|
6
|
-
:after_session => proc { |out, obj| out.puts "Ending Pry session for #{Pry.
|
5
|
+
:before_session => proc { |out, obj| out.puts "Beginning Pry session for #{Pry.view_clip(obj)}" },
|
6
|
+
:after_session => proc { |out, obj| out.puts "Ending Pry session for #{Pry.view_clip(obj)}" }
|
7
7
|
}
|
8
8
|
end
|
data/lib/pry/prompts.rb
CHANGED
@@ -1,20 +1,22 @@
|
|
1
1
|
class Pry
|
2
2
|
|
3
|
+
|
3
4
|
# The default prompt; includes the target and nesting level
|
4
5
|
DEFAULT_PROMPT = [
|
5
6
|
proc do |target_self, nest_level|
|
7
|
+
|
6
8
|
if nest_level == 0
|
7
|
-
"pry(#{Pry.
|
9
|
+
"pry(#{Pry.view_clip(target_self)})> "
|
8
10
|
else
|
9
|
-
"pry(#{Pry.
|
11
|
+
"pry(#{Pry.view_clip(target_self)}):#{Pry.view_clip(nest_level)}> "
|
10
12
|
end
|
11
13
|
end,
|
12
14
|
|
13
15
|
proc do |target_self, nest_level|
|
14
16
|
if nest_level == 0
|
15
|
-
"pry(#{Pry.
|
17
|
+
"pry(#{Pry.view_clip(target_self)})* "
|
16
18
|
else
|
17
|
-
"pry(#{Pry.
|
19
|
+
"pry(#{Pry.view_clip(target_self)}):#{Pry.view_clip(nest_level)}* "
|
18
20
|
end
|
19
21
|
end
|
20
22
|
]
|
data/lib/pry/pry_class.rb
CHANGED
@@ -81,6 +81,19 @@ class Pry
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
+
# A version of `Pry.view` that clips the output to `max_size` chars.
|
85
|
+
# In case of > `max_size` chars the `#<Object...> notation is used.
|
86
|
+
# @param obj The object to view.
|
87
|
+
# @param max_size The maximum number of chars before clipping occurs.
|
88
|
+
# @return [String] The string representation of `obj`.
|
89
|
+
def self.view_clip(obj, max_size=60)
|
90
|
+
if Pry.view(obj).size < max_size
|
91
|
+
Pry.view(obj)
|
92
|
+
else
|
93
|
+
"#<#{obj.class}:%#x>" % (obj.object_id << 1)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
84
97
|
# Set all the configurable options back to their default values
|
85
98
|
def self.reset_defaults
|
86
99
|
@input = Readline
|
@@ -104,4 +117,21 @@ class Pry
|
|
104
117
|
# last element in nesting array is the pry instance
|
105
118
|
nesting.map(&:last)
|
106
119
|
end
|
120
|
+
|
121
|
+
# Return a `Binding` object for `target` or return `target` if it is
|
122
|
+
# already a `Binding`.
|
123
|
+
# In the case where `target` is top-level then return `TOPLEVEL_BINDING`
|
124
|
+
# @param [Object] target The object to get a `Binding` object for.
|
125
|
+
# @return [Binding] The `Binding` object.
|
126
|
+
def self.binding_for(target)
|
127
|
+
if target.is_a?(Binding)
|
128
|
+
target
|
129
|
+
else
|
130
|
+
if target == TOPLEVEL_BINDING.eval('self')
|
131
|
+
TOPLEVEL_BINDING
|
132
|
+
else
|
133
|
+
target.__binding__
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
107
137
|
end
|
data/lib/pry/pry_instance.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'readline'
|
2
|
+
require 'shellwords'
|
2
3
|
|
3
4
|
class Pry
|
4
5
|
|
@@ -70,7 +71,7 @@ class Pry
|
|
70
71
|
# @example
|
71
72
|
# Pry.new.repl(Object.new)
|
72
73
|
def repl(target=TOPLEVEL_BINDING)
|
73
|
-
target = binding_for(target)
|
74
|
+
target = Pry.binding_for(target)
|
74
75
|
target_self = target.eval('self')
|
75
76
|
|
76
77
|
exec_hook :before_session, output, target_self
|
@@ -110,7 +111,7 @@ class Pry
|
|
110
111
|
# @example
|
111
112
|
# Pry.new.rep(Object.new)
|
112
113
|
def rep(target=TOPLEVEL_BINDING)
|
113
|
-
target = binding_for(target)
|
114
|
+
target = Pry.binding_for(target)
|
114
115
|
print.call output, re(target)
|
115
116
|
end
|
116
117
|
|
@@ -121,7 +122,7 @@ class Pry
|
|
121
122
|
# @example
|
122
123
|
# Pry.new.re(Object.new)
|
123
124
|
def re(target=TOPLEVEL_BINDING)
|
124
|
-
target = binding_for(target)
|
125
|
+
target = Pry.binding_for(target)
|
125
126
|
|
126
127
|
if input == Readline
|
127
128
|
# Readline tab completion
|
@@ -153,13 +154,17 @@ class Pry
|
|
153
154
|
# @example
|
154
155
|
# Pry.new.r(Object.new)
|
155
156
|
def r(target=TOPLEVEL_BINDING)
|
156
|
-
target = binding_for(target)
|
157
|
+
target = Pry.binding_for(target)
|
157
158
|
eval_string = ""
|
158
159
|
|
159
160
|
loop do
|
160
161
|
current_prompt = select_prompt(eval_string.empty?, target.eval('self'))
|
161
162
|
|
162
163
|
val = readline(current_prompt)
|
164
|
+
|
165
|
+
# exit pry if we receive EOF character
|
166
|
+
val = "quit" if !val
|
167
|
+
|
163
168
|
val.chomp!
|
164
169
|
|
165
170
|
process_commands(val, eval_string, target)
|
@@ -188,7 +193,7 @@ class Pry
|
|
188
193
|
|
189
194
|
if pattern
|
190
195
|
args_string = $1
|
191
|
-
args = args_string ? args_string
|
196
|
+
args = args_string ? Shellwords.shellwords(args_string) : []
|
192
197
|
action = data[:action]
|
193
198
|
|
194
199
|
options = {
|
@@ -288,21 +293,4 @@ class Pry
|
|
288
293
|
true
|
289
294
|
end
|
290
295
|
end
|
291
|
-
|
292
|
-
# Return a `Binding` object for `target` or return `target` if it is
|
293
|
-
# already a `Binding`.
|
294
|
-
# In the case where `target` is top-level then return `TOPLEVEL_BINDING`
|
295
|
-
# @param [Object] target The object to get a `Binding` object for.
|
296
|
-
# @return [Binding] The `Binding` object.
|
297
|
-
def binding_for(target)
|
298
|
-
if target.is_a?(Binding)
|
299
|
-
target
|
300
|
-
else
|
301
|
-
if target == TOPLEVEL_BINDING.eval('self')
|
302
|
-
TOPLEVEL_BINDING
|
303
|
-
else
|
304
|
-
target.__binding__
|
305
|
-
end
|
306
|
-
end
|
307
|
-
end
|
308
296
|
end
|
data/lib/pry/version.rb
CHANGED
data/test/test.rb
CHANGED
@@ -200,12 +200,12 @@ describe Pry do
|
|
200
200
|
end
|
201
201
|
end
|
202
202
|
|
203
|
-
describe "Pry
|
203
|
+
describe "Pry.binding_for" do
|
204
204
|
it 'should return TOPLEVEL_BINDING if parameter self is main' do
|
205
205
|
_main_ = lambda { TOPLEVEL_BINDING.eval('self') }
|
206
|
-
Pry.
|
207
|
-
Pry.
|
208
|
-
Pry.
|
206
|
+
Pry.binding_for(_main_.call).is_a?(Binding).should == true
|
207
|
+
Pry.binding_for(_main_.call).should == TOPLEVEL_BINDING
|
208
|
+
Pry.binding_for(_main_.call).should == Pry.binding_for(_main_.call)
|
209
209
|
end
|
210
210
|
end
|
211
211
|
|
@@ -346,7 +346,7 @@ describe Pry do
|
|
346
346
|
end
|
347
347
|
|
348
348
|
Command3.commands.include?("nesting").should == true
|
349
|
-
Command3.commands.include?("
|
349
|
+
Command3.commands.include?("jump-to").should == true
|
350
350
|
Command3.commands.include?("cd").should == true
|
351
351
|
Command3.commands.include?("v").should == true
|
352
352
|
|
@@ -422,7 +422,7 @@ describe Pry do
|
|
422
422
|
|
423
423
|
it 'should import commands from another command object' do
|
424
424
|
class Command3 < Pry::CommandBase
|
425
|
-
import_from Pry::Commands, "status", "
|
425
|
+
import_from Pry::Commands, "status", "jump-to"
|
426
426
|
end
|
427
427
|
|
428
428
|
str_output = StringIO.new
|
@@ -443,7 +443,7 @@ describe Pry do
|
|
443
443
|
end
|
444
444
|
|
445
445
|
Command3.commands.include?("nesting").should == true
|
446
|
-
Command3.commands.include?("
|
446
|
+
Command3.commands.include?("jump-to").should == true
|
447
447
|
Command3.commands.include?("cd").should == true
|
448
448
|
Command3.commands.include?("v").should == true
|
449
449
|
Command3.commands.include?("show_doc").should == false
|
@@ -455,8 +455,8 @@ describe Pry do
|
|
455
455
|
|
456
456
|
it 'should override some inherited commands' do
|
457
457
|
class Command3 < Pry::Commands
|
458
|
-
command "
|
459
|
-
output.puts "
|
458
|
+
command "jump-to" do
|
459
|
+
output.puts "jump-to the music"
|
460
460
|
end
|
461
461
|
|
462
462
|
command "help" do
|
@@ -468,8 +468,8 @@ describe Pry do
|
|
468
468
|
Pry.print = proc {}
|
469
469
|
|
470
470
|
str_output = StringIO.new
|
471
|
-
Pry.new(:input => InputTester.new("
|
472
|
-
str_output.string.chomp.should == "
|
471
|
+
Pry.new(:input => InputTester.new("jump-to"), :output => str_output, :commands => Command3).rep
|
472
|
+
str_output.string.chomp.should == "jump-to the music"
|
473
473
|
|
474
474
|
str_output = StringIO.new
|
475
475
|
Pry.new(:input => InputTester.new("help"), :output => str_output, :commands => Command3).rep
|
metadata
CHANGED
@@ -1,80 +1,56 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: pry
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 4
|
9
|
-
- 8
|
10
|
-
version: 0.4.8
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0pre2
|
5
|
+
prerelease: 5
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- John Mair (banisterfiend)
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2011-02-12 00:00:00 +13:00
|
12
|
+
date: 2011-02-17 00:00:00.000000000 +13:00
|
19
13
|
default_executable:
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
22
16
|
name: ruby_parser
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
17
|
+
requirement: &17857404 !ruby/object:Gem::Requirement
|
25
18
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 5
|
30
|
-
segments:
|
31
|
-
- 2
|
32
|
-
- 0
|
33
|
-
- 5
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
34
22
|
version: 2.0.5
|
35
23
|
type: :runtime
|
36
|
-
version_requirements: *id001
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: method_source
|
39
24
|
prerelease: false
|
40
|
-
|
25
|
+
version_requirements: *17857404
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: method_source
|
28
|
+
requirement: &17857080 !ruby/object:Gem::Requirement
|
41
29
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
hash: 23
|
46
|
-
segments:
|
47
|
-
- 0
|
48
|
-
- 2
|
49
|
-
- 0
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
50
33
|
version: 0.2.0
|
51
34
|
type: :runtime
|
52
|
-
version_requirements: *id002
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
name: bacon
|
55
35
|
prerelease: false
|
56
|
-
|
36
|
+
version_requirements: *17857080
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: bacon
|
39
|
+
requirement: &17856744 !ruby/object:Gem::Requirement
|
57
40
|
none: false
|
58
|
-
requirements:
|
59
|
-
- -
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
hash: 19
|
62
|
-
segments:
|
63
|
-
- 1
|
64
|
-
- 1
|
65
|
-
- 0
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
66
44
|
version: 1.1.0
|
67
45
|
type: :development
|
68
|
-
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *17856744
|
69
48
|
description: attach an irb-like session to any object at runtime
|
70
49
|
email: jrmair@gmail.com
|
71
50
|
executables: []
|
72
|
-
|
73
51
|
extensions: []
|
74
|
-
|
75
52
|
extra_rdoc_files: []
|
76
|
-
|
77
|
-
files:
|
53
|
+
files:
|
78
54
|
- lib/pry/commands.rb
|
79
55
|
- lib/pry/command_base.rb
|
80
56
|
- lib/pry/completion.rb
|
@@ -106,36 +82,26 @@ files:
|
|
106
82
|
has_rdoc: true
|
107
83
|
homepage: http://banisterfiend.wordpress.com
|
108
84
|
licenses: []
|
109
|
-
|
110
85
|
post_install_message:
|
111
86
|
rdoc_options: []
|
112
|
-
|
113
|
-
require_paths:
|
87
|
+
require_paths:
|
114
88
|
- lib
|
115
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
90
|
none: false
|
117
|
-
requirements:
|
118
|
-
- -
|
119
|
-
- !ruby/object:Gem::Version
|
120
|
-
|
121
|
-
|
122
|
-
- 0
|
123
|
-
version: "0"
|
124
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
96
|
none: false
|
126
|
-
requirements:
|
127
|
-
- -
|
128
|
-
- !ruby/object:Gem::Version
|
129
|
-
|
130
|
-
segments:
|
131
|
-
- 0
|
132
|
-
version: "0"
|
97
|
+
requirements:
|
98
|
+
- - ! '>'
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 1.3.1
|
133
101
|
requirements: []
|
134
|
-
|
135
102
|
rubyforge_project:
|
136
103
|
rubygems_version: 1.5.2
|
137
104
|
signing_key:
|
138
105
|
specification_version: 3
|
139
106
|
summary: attach an irb-like session to any object at runtime
|
140
107
|
test_files: []
|
141
|
-
|