pry 0.8.0pre1 → 0.8.0pre2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pry/TAGS +62 -0
- data/lib/pry/command_processor.rb +116 -0
- data/lib/pry/commands.rb +2 -0
- data/lib/pry/pry_instance.rb +7 -103
- data/lib/pry/version.rb +1 -1
- metadata +4 -2
data/lib/pry/TAGS
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
|
2
|
+
command_base.rb,124
|
3
|
+
attr_accessor :opts,opts8,206
|
4
|
+
attr_accessor :opts, :output,output8,206
|
5
|
+
commands[commands48,1817
|
6
|
+
|
7
|
+
command_processor.rb,25
|
8
|
+
ret_value 78,2169
|
9
|
+
|
10
|
+
commands.rb,488
|
11
|
+
direc 1,0
|
12
|
+
target 239,7098
|
13
|
+
target_self 326,9884
|
14
|
+
target.eval("self.class.constants(constants368,12413
|
15
|
+
new_constants 541,17465
|
16
|
+
process_yardoc_tag 586,19091
|
17
|
+
process_yardoc 602,19553
|
18
|
+
gsub(/^@(@606,19822
|
19
|
+
process_comment_markup 609,19917
|
20
|
+
strip_leading_hash_and_whitespace_from_ruby_comments 620,20291
|
21
|
+
target 629,20656
|
22
|
+
target 692,22513
|
23
|
+
options[options702,22857
|
24
|
+
text 848,27140
|
25
|
+
|
26
|
+
completion.rb,139
|
27
|
+
receiver 139,4449
|
28
|
+
lv 143,4577
|
29
|
+
cv 144,4642
|
30
|
+
candidates 152,5008
|
31
|
+
receiver 175,5682
|
32
|
+
|
33
|
+
core_extensions.rb,52
|
34
|
+
self.class.class_eval class_eval39,1245
|
35
|
+
|
36
|
+
custom_completions.rb,61
|
37
|
+
DEFAULT_CUSTOM_COMPLETIONS 4,81
|
38
|
+
FILE_COMPLETIONS 5,144
|
39
|
+
|
40
|
+
hooks.rb,22
|
41
|
+
DEFAULT_HOOKS 4,92
|
42
|
+
|
43
|
+
print.rb,23
|
44
|
+
DEFAULT_PRINT 5,109
|
45
|
+
|
46
|
+
prompts.rb,23
|
47
|
+
DEFAULT_PROMPT 5,76
|
48
|
+
|
49
|
+
pry_class.rb,116
|
50
|
+
RC_FILES 5,74
|
51
|
+
name,164,5591
|
52
|
+
name, arg_string 164,5591
|
53
|
+
null_output 174,5850
|
54
|
+
commands 176,5932
|
55
|
+
|
56
|
+
pry_instance.rb,77
|
57
|
+
direc 1,0
|
58
|
+
default_options 29,1134
|
59
|
+
instance_variable_set(34,1294
|
60
|
+
|
61
|
+
version.rb,16
|
62
|
+
VERSION 2,10
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
class Pry
|
4
|
+
class CommandProcessor
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
attr_reader :pry_instance
|
8
|
+
|
9
|
+
def initialize(pry_instance)
|
10
|
+
@pry_instance = pry_instance
|
11
|
+
end
|
12
|
+
|
13
|
+
def_delegators :@pry_instance, :commands, :nesting, :output
|
14
|
+
|
15
|
+
def system_command(val)
|
16
|
+
if val =~ /^\.(.*)/
|
17
|
+
execute_system_command($1)
|
18
|
+
val.clear
|
19
|
+
else
|
20
|
+
return false
|
21
|
+
end
|
22
|
+
true
|
23
|
+
end
|
24
|
+
|
25
|
+
def execute_system_command(cmd)
|
26
|
+
if cmd =~ /^cd\s+(.+)/i
|
27
|
+
Dir.chdir(File.expand_path($1))
|
28
|
+
system(cmd)
|
29
|
+
else
|
30
|
+
system(cmd)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Determine whether a Pry command was matched and return command data
|
35
|
+
# and argument string.
|
36
|
+
# This method should not need to be invoked directly.
|
37
|
+
# @param [String] val The line of input.
|
38
|
+
# @return [Array] The command data and arg string pair
|
39
|
+
def command_matched(val)
|
40
|
+
_, cmd_data = commands.commands.find do |name, cmd_data|
|
41
|
+
/^#{Regexp.escape(name)}(?!\S)(?:\s+(.+))?/ =~ val
|
42
|
+
end
|
43
|
+
|
44
|
+
[cmd_data, $1]
|
45
|
+
end
|
46
|
+
|
47
|
+
# Process Pry commands. Pry commands are not Ruby methods and are evaluated
|
48
|
+
# prior to Ruby expressions.
|
49
|
+
# Commands can be modified/configured by the user: see `Pry::Commands`
|
50
|
+
# This method should not need to be invoked directly - it is called
|
51
|
+
# by `Pry#r`.
|
52
|
+
# @param [String] val The current line of input.
|
53
|
+
# @param [String] eval_string The cumulative lines of input for
|
54
|
+
# multi-line input.
|
55
|
+
# @param [Binding] target The receiver of the commands.
|
56
|
+
def process_commands(val, eval_string, target)
|
57
|
+
def val.clear() replace("") end
|
58
|
+
def eval_string.clear() replace("") end
|
59
|
+
|
60
|
+
return if system_command(val)
|
61
|
+
|
62
|
+
cmd_data, args_string = command_matched(val)
|
63
|
+
|
64
|
+
# no command was matched, so return to caller
|
65
|
+
return if !cmd_data
|
66
|
+
|
67
|
+
args = args_string ? Shellwords.shellwords(args_string) : []
|
68
|
+
action = cmd_data[:action]
|
69
|
+
keep_retval = cmd_data[:keep_retval]
|
70
|
+
|
71
|
+
options = {
|
72
|
+
:val => val,
|
73
|
+
:eval_string => eval_string,
|
74
|
+
:nesting => nesting,
|
75
|
+
:commands => commands.commands
|
76
|
+
}
|
77
|
+
|
78
|
+
ret_value = execute_command(target, action, options, *args)
|
79
|
+
|
80
|
+
# return value of block only if :keep_retval is true
|
81
|
+
ret_value if keep_retval
|
82
|
+
end
|
83
|
+
|
84
|
+
# Execute a Pry command.
|
85
|
+
# This method should not need to be invoked directly.
|
86
|
+
# @param [Binding] target The target of the Pry session.
|
87
|
+
# @param [Proc] action The proc that implements the command.
|
88
|
+
# @param [Hash] options The options to set on the Commands object.
|
89
|
+
# @param [Array] args The command arguments.
|
90
|
+
def execute_command(target, action, options, *args)
|
91
|
+
|
92
|
+
# set some useful methods to be used by the action blocks
|
93
|
+
commands.opts = options
|
94
|
+
commands.target = target
|
95
|
+
commands.output = output
|
96
|
+
|
97
|
+
case action.arity <=> 0
|
98
|
+
when -1
|
99
|
+
|
100
|
+
# Use instance_exec() to make the `opts` method, etc available
|
101
|
+
ret_val = commands.instance_exec(*args, &action)
|
102
|
+
when 1, 0
|
103
|
+
|
104
|
+
# ensure that we get the right number of parameters
|
105
|
+
# since 1.8.7 complains about incorrect arity (1.9.2
|
106
|
+
# doesn't care)
|
107
|
+
args_with_corrected_arity = args.values_at *0..(action.arity - 1)
|
108
|
+
ret_val = commands.instance_exec(*args_with_corrected_arity, &action)
|
109
|
+
end
|
110
|
+
|
111
|
+
options[:val].clear
|
112
|
+
|
113
|
+
ret_val
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
data/lib/pry/commands.rb
CHANGED
data/lib/pry/pry_instance.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
direc = File.dirname(__FILE__)
|
2
|
+
|
3
|
+
require "#{direc}/command_processor.rb"
|
4
|
+
|
1
5
|
class Pry
|
2
6
|
|
3
7
|
# The list of configuration options.
|
@@ -29,6 +33,8 @@ class Pry
|
|
29
33
|
CONFIG_OPTIONS.each do |key|
|
30
34
|
instance_variable_set("@#{key}", default_options[key])
|
31
35
|
end
|
36
|
+
|
37
|
+
@command_processor = CommandProcessor.new(self)
|
32
38
|
end
|
33
39
|
|
34
40
|
# Get nesting data.
|
@@ -213,7 +219,7 @@ class Pry
|
|
213
219
|
# @target [Binding] target The target of the Pry session.
|
214
220
|
def process_line(val, eval_string, target)
|
215
221
|
val.chomp!
|
216
|
-
Pry.cmd_ret_value = process_commands(val, eval_string, target)
|
222
|
+
Pry.cmd_ret_value = @command_processor.process_commands(val, eval_string, target)
|
217
223
|
|
218
224
|
if Pry.cmd_ret_value
|
219
225
|
eval_string << "Pry.cmd_ret_value\n"
|
@@ -240,108 +246,6 @@ class Pry
|
|
240
246
|
target.eval("_ex_ = ::Pry.last_exception")
|
241
247
|
end
|
242
248
|
|
243
|
-
# FIXME
|
244
|
-
def system_command(val)
|
245
|
-
if val =~ /^:(.*)/
|
246
|
-
execute_system_command($1)
|
247
|
-
val.clear
|
248
|
-
else
|
249
|
-
return false
|
250
|
-
end
|
251
|
-
true
|
252
|
-
end
|
253
|
-
|
254
|
-
def execute_system_command(cmd)
|
255
|
-
if cmd =~ /^cd\s+(.+)/i
|
256
|
-
Dir.chdir(File.expand_path($1))
|
257
|
-
system(cmd)
|
258
|
-
else
|
259
|
-
system(cmd)
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
# Determine whether a Pry command was matched and return command data
|
264
|
-
# and argument string.
|
265
|
-
# This method should not need to be invoked directly.
|
266
|
-
# @param [String] val The line of input.
|
267
|
-
# @return [Array] The command data and arg string pair
|
268
|
-
def command_matched(val)
|
269
|
-
_, cmd_data = commands.commands.find do |name, cmd_data|
|
270
|
-
/^#{name}(?!\S)(?:\s+(.+))?/ =~ val
|
271
|
-
end
|
272
|
-
|
273
|
-
[cmd_data, $1]
|
274
|
-
end
|
275
|
-
|
276
|
-
# Process Pry commands. Pry commands are not Ruby methods and are evaluated
|
277
|
-
# prior to Ruby expressions.
|
278
|
-
# Commands can be modified/configured by the user: see `Pry::Commands`
|
279
|
-
# This method should not need to be invoked directly - it is called
|
280
|
-
# by `Pry#r`.
|
281
|
-
# @param [String] val The current line of input.
|
282
|
-
# @param [String] eval_string The cumulative lines of input for
|
283
|
-
# multi-line input.
|
284
|
-
# @param [Binding] target The receiver of the commands.
|
285
|
-
def process_commands(val, eval_string, target)
|
286
|
-
def val.clear() replace("") end
|
287
|
-
def eval_string.clear() replace("") end
|
288
|
-
|
289
|
-
return if system_command(val)
|
290
|
-
|
291
|
-
cmd_data, args_string = command_matched(val)
|
292
|
-
|
293
|
-
# no command was matched, so return to caller
|
294
|
-
return if !cmd_data
|
295
|
-
|
296
|
-
args = args_string ? Shellwords.shellwords(args_string) : []
|
297
|
-
action = cmd_data[:action]
|
298
|
-
keep_retval = cmd_data[:keep_retval]
|
299
|
-
|
300
|
-
options = {
|
301
|
-
:val => val,
|
302
|
-
:eval_string => eval_string,
|
303
|
-
:nesting => nesting,
|
304
|
-
:commands => commands.commands
|
305
|
-
}
|
306
|
-
|
307
|
-
ret_value = execute_command(target, action, options, *args)
|
308
|
-
|
309
|
-
# return value of block only if :keep_retval is true
|
310
|
-
ret_value if keep_retval
|
311
|
-
end
|
312
|
-
|
313
|
-
# Execute a Pry command.
|
314
|
-
# This method should not need to be invoked directly.
|
315
|
-
# @param [Binding] target The target of the Pry session.
|
316
|
-
# @param [Proc] action The proc that implements the command.
|
317
|
-
# @param [Hash] options The options to set on the Commands object.
|
318
|
-
# @param [Array] args The command arguments.
|
319
|
-
def execute_command(target, action, options, *args)
|
320
|
-
|
321
|
-
# set some useful methods to be used by the action blocks
|
322
|
-
commands.opts = options
|
323
|
-
commands.target = target
|
324
|
-
commands.output = output
|
325
|
-
|
326
|
-
case action.arity <=> 0
|
327
|
-
when -1
|
328
|
-
|
329
|
-
# Use instance_exec() to make the `opts` method, etc available
|
330
|
-
ret_val = commands.instance_exec(*args, &action)
|
331
|
-
when 1, 0
|
332
|
-
|
333
|
-
# ensure that we get the right number of parameters
|
334
|
-
# since 1.8.7 complains about incorrect arity (1.9.2
|
335
|
-
# doesn't care)
|
336
|
-
args_with_corrected_arity = args.values_at *0..(action.arity - 1)
|
337
|
-
ret_val = commands.instance_exec(*args_with_corrected_arity, &action)
|
338
|
-
end
|
339
|
-
|
340
|
-
options[:val].clear
|
341
|
-
|
342
|
-
ret_val
|
343
|
-
end
|
344
|
-
|
345
249
|
# Returns the next line of input to be used by the pry instance.
|
346
250
|
# This method should not need to be invoked directly.
|
347
251
|
# @param [String] current_prompt The prompt to use for input.
|
data/lib/pry/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 8
|
8
|
-
-
|
9
|
-
version: 0.8.
|
8
|
+
- 0pre2
|
9
|
+
version: 0.8.0pre2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- John Mair (banisterfiend)
|
@@ -88,11 +88,13 @@ extra_rdoc_files: []
|
|
88
88
|
files:
|
89
89
|
- lib/pry/commands.rb
|
90
90
|
- lib/pry/version.rb
|
91
|
+
- lib/pry/TAGS
|
91
92
|
- lib/pry/command_base.rb
|
92
93
|
- lib/pry/prompts.rb
|
93
94
|
- lib/pry/hooks.rb
|
94
95
|
- lib/pry/custom_completions.rb
|
95
96
|
- lib/pry/core_extensions.rb
|
97
|
+
- lib/pry/command_processor.rb
|
96
98
|
- lib/pry/completion.rb
|
97
99
|
- lib/pry/print.rb
|
98
100
|
- lib/pry/pry_class.rb
|