pry 0.7.6.1-i386-mingw32 → 0.7.7-i386-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +2 -1
- data/lib/pry.rb +0 -1
- data/lib/pry/commands.rb +19 -7
- data/lib/pry/pry_instance.rb +73 -35
- data/lib/pry/version.rb +1 -1
- metadata +3 -4
data/README.markdown
CHANGED
@@ -247,7 +247,8 @@ If you want to access a method of the same name, prefix the invocation by whites
|
|
247
247
|
getting you out of a situation where the parsing process
|
248
248
|
goes wrong and you get stuck in an endless read loop.
|
249
249
|
* `status` shows status information about the current session.
|
250
|
-
* `whereami` shows the code context of the session.
|
250
|
+
* `whereami AROUND` shows the code context of the session. Shows
|
251
|
+
AROUND lines either side of the current line.
|
251
252
|
* `version` Show Pry version information
|
252
253
|
* `help` shows the list of session commands with brief explanations.
|
253
254
|
* `toggle-color` turns on and off syntax highlighting.
|
data/lib/pry.rb
CHANGED
data/lib/pry/commands.rb
CHANGED
@@ -4,7 +4,11 @@ require "pry/command_base"
|
|
4
4
|
require "pry/pry_instance"
|
5
5
|
|
6
6
|
begin
|
7
|
-
|
7
|
+
|
8
|
+
# YARD crashes on rbx, so do not require it
|
9
|
+
if !Object_const_defined?(:RUBY_ENGINE) || RUBY_ENGINE !~ /rbx/
|
10
|
+
require "pry-doc"
|
11
|
+
end
|
8
12
|
rescue LoadError
|
9
13
|
end
|
10
14
|
|
@@ -469,11 +473,19 @@ e.g: eval-file -c self "hello.rb"
|
|
469
473
|
gsub(/\B\+(\w*?)\+\B/) { Pry.color ? "\e[32m#{$1}\e[0m": $1 }.
|
470
474
|
gsub(/((?:^[ \t]+.+(?:\n+|\Z))+)/) { Pry.color ? CodeRay.scan($1, code_type).term : $1 }.
|
471
475
|
gsub(/`(?:\s*\n)?(.*?)\s*`/) { Pry.color ? CodeRay.scan($1, code_type).term : $1 }.
|
472
|
-
gsub(
|
476
|
+
gsub(/^@(param|return|example|option|yield|attr|attr_reader|attr_writer)/) { Pry.color ? "\e[33m#{$1}\e[0m": $1 }
|
477
|
+
end
|
478
|
+
|
479
|
+
# strip leading whitespace but preserve indentation
|
480
|
+
strip_leading_whitespace = lambda do |text|
|
481
|
+
leading_spaces = text.lines.first[/^(\s+)/, 1]
|
482
|
+
text.gsub(/^#{leading_spaces}/, '')
|
473
483
|
end
|
474
484
|
|
475
|
-
|
476
|
-
comment
|
485
|
+
strip_leading_hash_and_whitespace_from_ruby_comments = lambda do |comment|
|
486
|
+
comment = comment.dup
|
487
|
+
comment.gsub!(/^\s*#/, '')
|
488
|
+
strip_leading_whitespace.call(comment)
|
477
489
|
end
|
478
490
|
|
479
491
|
command "show-doc", "Show the comments above METH. Type `show-doc --help` for more info." do |*args|
|
@@ -521,7 +533,7 @@ e.g show-doc hello_method
|
|
521
533
|
doc = Pry::MethodInfo.info_for(meth).docstring
|
522
534
|
when :ruby
|
523
535
|
doc = meth.comment
|
524
|
-
doc =
|
536
|
+
doc = strip_leading_hash_and_whitespace_from_ruby_comments.call(doc)
|
525
537
|
end
|
526
538
|
|
527
539
|
doc = process_comment_markup.call(doc, code_type)
|
@@ -581,7 +593,7 @@ e.g: show-method hello_method
|
|
581
593
|
code = Pry::MethodInfo.info_for(meth).source
|
582
594
|
code = strip_comments_from_c_code.call(code)
|
583
595
|
when :ruby
|
584
|
-
code = meth.source
|
596
|
+
code = strip_leading_whitespace.call(meth.source)
|
585
597
|
end
|
586
598
|
|
587
599
|
output.puts make_header.call(meth, code_type)
|
@@ -604,7 +616,7 @@ e.g: show-method hello_method
|
|
604
616
|
if commands[command_name]
|
605
617
|
meth = commands[command_name][:action]
|
606
618
|
|
607
|
-
code = meth.source
|
619
|
+
code = strip_leading_whitespace.call(meth.source)
|
608
620
|
file, line = meth.source_location
|
609
621
|
check_for_dynamically_defined_method.call(meth)
|
610
622
|
|
data/lib/pry/pry_instance.rb
CHANGED
@@ -15,11 +15,9 @@ class Pry
|
|
15
15
|
# @param [Hash] options The optional configuration parameters.
|
16
16
|
# @option options [#readline] :input The object to use for input.
|
17
17
|
# @option options [#puts] :output The object to use for output.
|
18
|
-
# @option options [Pry::CommandBase] :commands The object to use for
|
19
|
-
# commands. (see commands.rb)
|
18
|
+
# @option options [Pry::CommandBase] :commands The object to use for commands. (see commands.rb)
|
20
19
|
# @option options [Hash] :hooks The defined hook Procs (see hooks.rb)
|
21
|
-
# @option options [Array<Proc>] :default_prompt The array of Procs
|
22
|
-
# to use for the prompts. (see prompts.rb)
|
20
|
+
# @option options [Array<Proc>] :default_prompt The array of Procs to use for the prompts. (see prompts.rb)
|
23
21
|
# @option options [Proc] :print The Proc to use for the 'print'
|
24
22
|
# component of the REPL. (see print.rb)
|
25
23
|
def initialize(options={})
|
@@ -184,31 +182,48 @@ class Pry
|
|
184
182
|
eval_string = ""
|
185
183
|
|
186
184
|
loop do
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
if !val
|
193
|
-
output.puts
|
194
|
-
throw(:breakout, nesting.level)
|
195
|
-
end
|
196
|
-
|
197
|
-
val.chomp!
|
198
|
-
|
199
|
-
Pry.cmd_ret_value = process_commands(val, eval_string, target)
|
185
|
+
val = retrieve_line(eval_string, target)
|
186
|
+
process_line(val, eval_string, target)
|
187
|
+
break eval_string if valid_expression?(eval_string)
|
188
|
+
end
|
189
|
+
end
|
200
190
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
191
|
+
# Read a line of input and check for ^d, also determine prompt to use.
|
192
|
+
# This method should not need to be invoked directly.
|
193
|
+
# @param [String] eval_string The cumulative lines of input.
|
194
|
+
# @param [Binding] target The target of the session.
|
195
|
+
# @return [String] The line received.
|
196
|
+
def retrieve_line(eval_string, target)
|
197
|
+
current_prompt = select_prompt(eval_string.empty?, target.eval('self'))
|
198
|
+
val = readline(current_prompt)
|
199
|
+
|
200
|
+
# exit session if we receive EOF character
|
201
|
+
if !val
|
202
|
+
output.puts
|
203
|
+
throw(:breakout, nesting.level)
|
204
|
+
end
|
205
|
+
|
206
|
+
val
|
207
|
+
end
|
206
208
|
|
207
|
-
|
209
|
+
# Process the line received.
|
210
|
+
# This method should not need to be invoked directly.
|
211
|
+
# @param [String] val The line to process.
|
212
|
+
# @param [String] eval_string The cumulative lines of input.
|
213
|
+
# @target [Binding] target The target of the Pry session.
|
214
|
+
def process_line(val, eval_string, target)
|
215
|
+
val.chomp!
|
216
|
+
Pry.cmd_ret_value = process_commands(val, eval_string, target)
|
217
|
+
|
218
|
+
if Pry.cmd_ret_value
|
219
|
+
eval_string << "Pry.cmd_ret_value\n"
|
220
|
+
else
|
221
|
+
eval_string << "#{val}\n"
|
208
222
|
end
|
209
223
|
end
|
210
224
|
|
211
225
|
# Set the last result of an eval.
|
226
|
+
# This method should not need to be invoked directly.
|
212
227
|
# @param [Object] result The result.
|
213
228
|
# @param [Binding] target The binding to set `_` on.
|
214
229
|
def set_last_result(result, target)
|
@@ -217,6 +232,7 @@ class Pry
|
|
217
232
|
end
|
218
233
|
|
219
234
|
# Set the last exception for a session.
|
235
|
+
# This method should not need to be invoked directly.
|
220
236
|
# @param [Exception] ex The exception.
|
221
237
|
# @param [Binding] target The binding to set `_ex_` on.
|
222
238
|
def set_last_exception(ex, target)
|
@@ -224,6 +240,19 @@ class Pry
|
|
224
240
|
target.eval("_ex_ = Pry.last_exception")
|
225
241
|
end
|
226
242
|
|
243
|
+
# Determine whether a Pry command was matched and return command data
|
244
|
+
# and argument string.
|
245
|
+
# This method should not need to be invoked directly.
|
246
|
+
# @param [String] val The line of input.
|
247
|
+
# @return [Array] The command data and arg string pair
|
248
|
+
def command_matched(val)
|
249
|
+
_, cmd_data = commands.commands.find do |name, cmd_data|
|
250
|
+
/^#{name}(?!\S)(?:\s+(.+))?/ =~ val
|
251
|
+
end
|
252
|
+
|
253
|
+
[cmd_data, $1]
|
254
|
+
end
|
255
|
+
|
227
256
|
# Process Pry commands. Pry commands are not Ruby methods and are evaluated
|
228
257
|
# prior to Ruby expressions.
|
229
258
|
# Commands can be modified/configured by the user: see `Pry::Commands`
|
@@ -237,14 +266,11 @@ class Pry
|
|
237
266
|
def val.clear() replace("") end
|
238
267
|
def eval_string.clear() replace("") end
|
239
268
|
|
240
|
-
|
241
|
-
/^#{name}(?!\S)(?:\s+(.+))?/ =~ val
|
242
|
-
end
|
269
|
+
cmd_data, args_string = command_matched(val)
|
243
270
|
|
244
271
|
# no command was matched, so return to caller
|
245
|
-
return if !
|
272
|
+
return if !cmd_data
|
246
273
|
|
247
|
-
args_string = $1
|
248
274
|
args = args_string ? Shellwords.shellwords(args_string) : []
|
249
275
|
action = cmd_data[:action]
|
250
276
|
keep_retval = cmd_data[:keep_retval]
|
@@ -256,6 +282,20 @@ class Pry
|
|
256
282
|
:commands => commands.commands
|
257
283
|
}
|
258
284
|
|
285
|
+
ret_value = execute_command(target, action, options, *args)
|
286
|
+
|
287
|
+
# return value of block only if :keep_retval is true
|
288
|
+
ret_value if keep_retval
|
289
|
+
end
|
290
|
+
|
291
|
+
# Execute a Pry command.
|
292
|
+
# This method should not need to be invoked directly.
|
293
|
+
# @param [Binding] target The target of the Pry session.
|
294
|
+
# @param [Proc] action The proc that implements the command.
|
295
|
+
# @param [Hash] options The options to set on the Commands object.
|
296
|
+
# @param [Array] args The command arguments.
|
297
|
+
def execute_command(target, action, options, *args)
|
298
|
+
|
259
299
|
# set some useful methods to be used by the action blocks
|
260
300
|
commands.opts = options
|
261
301
|
commands.target = target
|
@@ -265,21 +305,19 @@ class Pry
|
|
265
305
|
when -1
|
266
306
|
|
267
307
|
# Use instance_exec() to make the `opts` method, etc available
|
268
|
-
|
308
|
+
ret_val = commands.instance_exec(*args, &action)
|
269
309
|
when 1, 0
|
270
310
|
|
271
311
|
# ensure that we get the right number of parameters
|
272
312
|
# since 1.8.7 complains about incorrect arity (1.9.2
|
273
313
|
# doesn't care)
|
274
314
|
args_with_corrected_arity = args.values_at *0..(action.arity - 1)
|
275
|
-
|
315
|
+
ret_val = commands.instance_exec(*args_with_corrected_arity, &action)
|
276
316
|
end
|
277
|
-
|
278
|
-
# a command was processed so we can now clear the input string
|
279
|
-
val.clear
|
280
317
|
|
281
|
-
|
282
|
-
|
318
|
+
options[:val].clear
|
319
|
+
|
320
|
+
ret_val
|
283
321
|
end
|
284
322
|
|
285
323
|
# Returns the next line of input to be used by the pry instance.
|
data/lib/pry/version.rb
CHANGED
metadata
CHANGED
@@ -5,9 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 7
|
8
|
-
-
|
9
|
-
|
10
|
-
version: 0.7.6.1
|
8
|
+
- 7
|
9
|
+
version: 0.7.7
|
11
10
|
platform: i386-mingw32
|
12
11
|
authors:
|
13
12
|
- John Mair (banisterfiend)
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2011-
|
17
|
+
date: 2011-04-01 00:00:00 +13:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|