pry 0.9.2 → 0.9.3pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG +17 -0
- data/README.markdown +18 -187
- data/Rakefile +2 -2
- data/TODO +14 -7
- data/bin/pry +1 -1
- data/lib/pry.rb +6 -2
- data/lib/pry/command_context.rb +9 -0
- data/lib/pry/command_processor.rb +4 -1
- data/lib/pry/command_set.rb +8 -4
- data/lib/pry/config.rb +16 -4
- data/lib/pry/default_commands/basic.rb +19 -2
- data/lib/pry/default_commands/input.rb +7 -5
- data/lib/pry/default_commands/introspection.rb +36 -13
- data/lib/pry/default_commands/shell.rb +31 -2
- data/lib/pry/extended_commands/experimental.rb +0 -61
- data/lib/pry/plugins.rb +1 -1
- data/lib/pry/pry_class.rb +14 -1
- data/lib/pry/version.rb +1 -1
- data/test/helper.rb +4 -1
- data/test/test_command_processor.rb +51 -1
- data/test/test_default_commands/test_input.rb +9 -9
- data/test/test_pry.rb +31 -1
- metadata +8 -8
data/.gitignore
CHANGED
data/CHANGELOG
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
*/7/2011 version 0.9.3
|
2
|
+
* cat --ex (cats 5 lines above and below line in file where exception was raised)
|
3
|
+
* edit --ex (edits line in file where exception was raised)
|
4
|
+
* edit -t (opens a temporary file and evals it in current context when closed)
|
5
|
+
* `pry -r` requires now happen after plugin loading (so as not to interfere with
|
6
|
+
* new Pry.config.disable_auto_reload option, for turning off auto reloading by edit-method and related (thanks ryanf)
|
7
|
+
* add better error messages for `cd` command
|
8
|
+
* fixed exotic object regression - BasicObject.new etc now return "=> unknown"
|
9
|
+
* added reload-method command (reloads the associated file of a method)
|
10
|
+
* converted: import => import-set, version => pry-version, install => install-command
|
11
|
+
* Pry.config.command_prefix support (thanks ryanf!)
|
12
|
+
* fixed indentation for simple-prompt
|
13
|
+
* hist command now excludes last line of input (the command invocation itself)
|
14
|
+
* hist now has `history` alias
|
15
|
+
* missing plugins no longer raise exception, just print a warning to $stderr
|
16
|
+
* fixed jedit editor support
|
17
|
+
|
1
18
|
21/6/2011 version 0.9.2
|
2
19
|
* fixed string interpolation bug (caused valid ruby code not to execute, sorry!)
|
3
20
|
* fixed `ls` command, so it can properly display members of Object and classes, and BasicObject, etc
|
data/README.markdown
CHANGED
@@ -4,14 +4,11 @@
|
|
4
4
|
|
5
5
|
_Get to the code_
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
** New documentation will be available shortly, please see the CHANGELOG and Pry's own livehelp system for information in the meantime.
|
10
|
-
|
11
|
-
Also note that JRuby is not yet supported in this release, but will be soon.
|
12
|
-
|
13
|
-
Thanks **
|
7
|
+
**Note that JRuby is not yet supported in this release, but will be
|
8
|
+
soon.**
|
14
9
|
|
10
|
+
[Skip to the website](http://pry.github.com) <br />
|
11
|
+
[Skip to the wiki](https://github.com/pry/pry/wiki)
|
15
12
|
|
16
13
|
Pry is a powerful alternative to the standard IRB shell for Ruby. It is
|
17
14
|
written from scratch to provide a number of advanced features, some of
|
@@ -37,7 +34,7 @@ currently not nearly as powerful as tools like [SLIME](http://en.wikipedia.org/w
|
|
37
34
|
general direction Pry is heading.
|
38
35
|
|
39
36
|
Pry is also fairly flexible and allows significant user
|
40
|
-
[customization](
|
37
|
+
[customization](https://github.com/pry/pry/wiki/Customization-and-configuration)
|
41
38
|
is trivial to set it to read from any object that has a `readline` method and write to any object that has a
|
42
39
|
`puts` method - many other aspects of Pry are also configurable making
|
43
40
|
it a good choice for implementing custom shells.
|
@@ -52,8 +49,9 @@ methods. The additional docs are accessed through the `show-doc` and
|
|
52
49
|
`show-method` commands.
|
53
50
|
|
54
51
|
* Install the [gem](https://rubygems.org/gems/pry): `gem install pry`
|
55
|
-
*
|
56
|
-
*
|
52
|
+
* Browse the comprehensive [documentation at the official Pry wiki](https://github.com/pry/pry/wiki)
|
53
|
+
* Read the [YARD API documentation](http://rdoc.info/github/pry/pry/master/file/README.markdown)
|
54
|
+
* See the [source code](http://github.com/pry/pry)
|
57
55
|
|
58
56
|
Pry also has `rubygems-test` support; to participate, first install
|
59
57
|
Pry, then:
|
@@ -71,7 +69,7 @@ whitespace in between. Commands support a flexible syntax and allow
|
|
71
69
|
Pry command will show a list of all private instance methods (in
|
72
70
|
scope) that begin with 'pa'
|
73
71
|
|
74
|
-
pry(YARD::Parser::SourceParser):5> ls -Mp --grep pa
|
72
|
+
pry(YARD::Parser::SourceParser):5> ls -Mp --grep ^pa
|
75
73
|
[:parser_class, :parser_type=, :parser_type_for_filename]
|
76
74
|
|
77
75
|
### Navigating around state
|
@@ -202,8 +200,6 @@ current directory and count the number of lines in that file with
|
|
202
200
|
|
203
201
|
### Code Browsing
|
204
202
|
|
205
|
-
#### show-method
|
206
|
-
|
207
203
|
You can browse method source code with the `show-method` command. Nearly all Ruby methods (and some C methods, with the pry-doc
|
208
204
|
gem) can have their source viewed. Code that is longer than a page is
|
209
205
|
sent through a pager (such as less), and all code is properly syntax
|
@@ -233,7 +229,7 @@ instance methods beginning with 're' and display the source code for the `rep` m
|
|
233
229
|
148: end
|
234
230
|
|
235
231
|
Note that we can also view C methods (from Ruby Core) using the
|
236
|
-
`pry-doc`
|
232
|
+
`pry-doc` plugin; we also show off the alternate syntax for
|
237
233
|
`show-method`:
|
238
234
|
|
239
235
|
pry(main)> show-method Array#select
|
@@ -257,47 +253,6 @@ Note that we can also view C methods (from Ruby Core) using the
|
|
257
253
|
return result;
|
258
254
|
}
|
259
255
|
|
260
|
-
#### Special locals
|
261
|
-
|
262
|
-
Some commands such as `show-method`, `show-doc`, `show-command`, `stat`
|
263
|
-
and `cat` update the `_file_` and `_dir_` local variables after they
|
264
|
-
run. These locals contain the full path to the file involved in the
|
265
|
-
last command as well as the directory containing that file.
|
266
|
-
|
267
|
-
You can then use these special locals in conjunction with shell
|
268
|
-
commands to do such things as change directory into the directory
|
269
|
-
containing the file, open the file in an editor, display the file using `cat`, and so on.
|
270
|
-
|
271
|
-
In the following example we wil use Pry to fix a bug in a method:
|
272
|
-
|
273
|
-
pry(main)> greet "john"
|
274
|
-
hello johnhow are you?=> nil
|
275
|
-
pry(main)> show-method greet
|
276
|
-
|
277
|
-
From: /Users/john/ruby/play/bug.rb @ line 2:
|
278
|
-
Number of lines: 4
|
279
|
-
|
280
|
-
def greet(name)
|
281
|
-
print "hello #{name}"
|
282
|
-
print "how are you?"
|
283
|
-
end
|
284
|
-
pry(main)> .emacsclient #{_file_}
|
285
|
-
pry(main)> load _file_
|
286
|
-
pry(main)> greet "john"
|
287
|
-
hello john
|
288
|
-
how are you?
|
289
|
-
=> nil
|
290
|
-
pry(main)> show-method greet
|
291
|
-
|
292
|
-
From: /Users/john/ruby/play/bug.rb @ line 2:
|
293
|
-
Number of lines: 4
|
294
|
-
|
295
|
-
def greet(name)
|
296
|
-
puts "hello #{name}"
|
297
|
-
puts "how are you?"
|
298
|
-
end
|
299
|
-
|
300
|
-
|
301
256
|
### Documentation Browsing
|
302
257
|
|
303
258
|
One use-case for Pry is to explore a program at run-time by `cd`-ing
|
@@ -352,63 +307,6 @@ We can also use `ri` in the normal way:
|
|
352
307
|
|
353
308
|
a -- b -- c --
|
354
309
|
|
355
|
-
|
356
|
-
### History
|
357
|
-
|
358
|
-
Readline history can be viewed and replayed using the `hist`
|
359
|
-
command. When `hist` is invoked with no arguments it simply displays
|
360
|
-
the history (passing the output through a pager if necessary))
|
361
|
-
when the `--replay` option is used a line or a range of lines of
|
362
|
-
history can be replayed.
|
363
|
-
|
364
|
-
In the example below we will enter a few lines in a Pry session and
|
365
|
-
then view history; we will then replay one of those lines:
|
366
|
-
|
367
|
-
pry(main)> hist
|
368
|
-
0: hist -h
|
369
|
-
1: ls
|
370
|
-
2: ls
|
371
|
-
3: show-method puts
|
372
|
-
4: x = rand
|
373
|
-
5: hist
|
374
|
-
pry(main)> hist --replay 3
|
375
|
-
|
376
|
-
From: io.c in Ruby Core (C Method):
|
377
|
-
Number of lines: 8
|
378
|
-
|
379
|
-
static VALUE
|
380
|
-
rb_f_puts(int argc, VALUE *argv, VALUE recv)
|
381
|
-
{
|
382
|
-
if (recv == rb_stdout) {
|
383
|
-
return rb_io_puts(argc, argv, recv);
|
384
|
-
}
|
385
|
-
return rb_funcall2(rb_stdout, rb_intern("puts"), argc, argv);
|
386
|
-
}
|
387
|
-
|
388
|
-
In the next example we will replay a range of lines in history. Note
|
389
|
-
that we replay to a point where a class definition is still open and so
|
390
|
-
we can continue to add instance methods to the class:
|
391
|
-
|
392
|
-
pry(main)> hist
|
393
|
-
0: class Hello
|
394
|
-
1: def hello_world
|
395
|
-
2: puts "hello world!"
|
396
|
-
3: end
|
397
|
-
4: end
|
398
|
-
5: hist
|
399
|
-
pry(main)> hist --replay 0..3
|
400
|
-
pry(main)* def goodbye_world
|
401
|
-
pry(main)* puts "goodbye world!"
|
402
|
-
pry(main)* end
|
403
|
-
pry(main)* end
|
404
|
-
=> nil
|
405
|
-
pry(main)> Hello.new.goodbye_world;
|
406
|
-
goodbye world!
|
407
|
-
pry(main)>
|
408
|
-
|
409
|
-
Also note that in the above the line `Hello.new.goodbye_world;` ends
|
410
|
-
with a semi-colon which causes expression evaluation output to be suppressed.
|
411
|
-
|
412
310
|
### Gist integration
|
413
311
|
|
414
312
|
If the `gist` gem is installed then method source or documentation can be gisted to github with the
|
@@ -456,54 +354,12 @@ avaiable.
|
|
456
354
|
|
457
355
|
MyArtChannel has kindly provided a hack to replace the `rails console` command in Rails 3: [https://gist.github.com/941174](https://gist.github.com/941174) This is not recommended for code bases with multiple developers, as they may not all want to use Pry.
|
458
356
|
|
459
|
-
###
|
460
|
-
|
461
|
-
#### Other Features:
|
462
|
-
|
463
|
-
* Pry can be invoked both at the command-line and used as a more
|
464
|
-
powerful alternative to IRB or it can be invoked at runtime and used
|
465
|
-
as a developer consoler / debugger.
|
466
|
-
* Additional documentation and source code for Ruby Core methods are supported when the `pry-doc` gem is installed.
|
467
|
-
* Pry sessions can nest arbitrarily deeply -- to go back one level of nesting type 'exit' or 'quit' or 'back'
|
468
|
-
* Pry comes with syntax highlighting on by default just use the `toggle-color` command to turn it on and off.
|
469
|
-
* Use `_` to recover last result.
|
470
|
-
* Use `_pry_` to reference the Pry instance managing the current session.
|
471
|
-
* Use `_ex_` to recover the last exception.
|
472
|
-
* Use `_file_` and `_dir_` to refer to the associated file or
|
473
|
-
directory containing the definition for a method.
|
474
|
-
* A trailing `;` on an entered expression suppresses the display of
|
475
|
-
the evaluation output.
|
476
|
-
* Typing `!` on a line by itself will clear the input buffer - useful for
|
477
|
-
getting you out of a situation where the parsing process
|
478
|
-
goes wrong and you get stuck in an endless read loop.
|
479
|
-
* Pry supports tab completion.
|
480
|
-
* Pry has multi-line support built in.
|
481
|
-
* Use `^d` (control-d) to quickly break out of a session.
|
482
|
-
* Pry has special commands not found in many other Ruby REPLs: `show-method`, `show-doc`
|
483
|
-
`jump-to`, `ls`, `cd`, `cat`
|
484
|
-
* Pry gives good control over nested sessions (important when exploring complicated runtime state)
|
485
|
-
* Pry is not based on the IRB codebase.
|
486
|
-
* Pry allows significant customizability.
|
487
|
-
* Pry uses the [method_source](https://github.com/banister/method_source) gem; so
|
488
|
-
this functionality is available to a Pry session.
|
489
|
-
* Pry uses [RubyParser](https://github.com/seattlerb/ruby_parser) to
|
490
|
-
validate expressions in 1.8, and [Ripper](http://rdoc.info/docs/ruby-core/1.9.2/Ripper) for 1.9.
|
491
|
-
* Pry implements all the methods in the REPL chain separately: `Pry#r`
|
492
|
-
for reading; `Pry#re` for eval; `Pry#rep` for printing; and `Pry#repl`
|
493
|
-
for the loop (`Pry.start` simply wraps `Pry.new.repl`). You can
|
494
|
-
invoke any of these methods directly depending on exactly what aspect of the functionality you need.
|
495
|
-
|
496
|
-
#### Limitations:
|
497
|
-
|
498
|
-
* Some Pry commands (e.g `show-command`) do not work in Ruby 1.8
|
499
|
-
MRI. But many other commands do work in Ruby 1.8 MRI, e.g
|
500
|
-
`show-method`, due to a functional 1.8 source_location implementation.
|
357
|
+
### Limitations:
|
358
|
+
|
501
359
|
* JRuby not officially supported due to currently too many quirks and
|
502
|
-
strange behaviour.
|
503
|
-
OK in JRuby. Full JRuby support coming in a future version.
|
504
|
-
* `method_source` functionality does not work in JRuby with Ruby 1.8
|
360
|
+
strange behaviour. This will be fixed soon.
|
505
361
|
* Tab completion is currently a bit broken/limited this will have a
|
506
|
-
|
362
|
+
major overhaul in a future version.
|
507
363
|
|
508
364
|
### Syntax Highlighting
|
509
365
|
|
@@ -512,40 +368,15 @@ off in a session by using the `toggle-color` command. Alternatively,
|
|
512
368
|
you can turn it off permanently by putting the line `Pry.color =
|
513
369
|
false` in your `~/.pryrc` file.
|
514
370
|
|
515
|
-
### Example Programs
|
516
|
-
|
517
|
-
Pry comes bundled with a few example programs to illustrate some
|
518
|
-
features, see the `examples/` directory.
|
519
|
-
|
520
|
-
* `example_basic.rb` - Demonstrate basic Pry functionality
|
521
|
-
* `example_input.rb` - Demonstrates how to set the `input` object.
|
522
|
-
* `example_output.rb` - Demonstrates how to set the `output` object.
|
523
|
-
* `example_hooks.rb` - Demonstrates how to set the `hooks` hash.
|
524
|
-
* `example_print.rb` - Demonstrates how to set the `print` object.
|
525
|
-
* `example_prompt.rb` - Demonstrates how to set the `prompt`.
|
526
|
-
* `example_input2.rb` - An advanced `input` example.
|
527
|
-
* `example_commands.rb` - Implementing a mathematical command set.
|
528
|
-
* `example_commands_override.rb` - An advanced `commands` example.
|
529
|
-
* `example_image_edit.rb` - A simple image editor using a Pry REPL (requires `Gosu` and `TexPlay` gems).
|
530
|
-
|
531
|
-
### Customizing Pry
|
532
|
-
|
533
|
-
Pry allows a large degree of customization.
|
534
|
-
|
535
|
-
[Read how to customize Pry here.](http://rdoc.info/github/banister/pry/master/file/wiki/Customizing-pry.md)
|
536
|
-
|
537
371
|
### Future Directions
|
538
372
|
|
539
373
|
Many new features are planned such as:
|
540
374
|
|
375
|
+
* Increase modularity (rely more on plugin system)
|
541
376
|
* Much improved tab completion (using [Bond](http://github.com/cldwalker/bond))
|
542
377
|
* Improved JRuby support
|
543
|
-
* Support for viewing source-code of binary gems and C stdlib
|
544
|
-
* git integration
|
545
378
|
* Much improved documentation system, better support for YARD
|
546
|
-
*
|
547
|
-
* Get rid of `.` prefix for shell commands in `shell-mode`
|
548
|
-
* Better support for code and method reloading
|
379
|
+
* Better support for code and method reloading and saving code
|
549
380
|
* Extended and more sophisticated command system, allowing piping
|
550
381
|
between commands and running commands in background
|
551
382
|
|
@@ -558,6 +389,6 @@ Problems or questions contact me at [github](http://github.com/banister)
|
|
558
389
|
The Pry team consists of:
|
559
390
|
|
560
391
|
* [banisterfiend](http://github.com/banister)
|
561
|
-
* [injekt](http://github.com/injekt)
|
562
|
-
* [Mon_Ouie](http://github.com/mon-ouie)
|
563
392
|
* [Rob Gleeson](https://github.com/robgleeson)
|
393
|
+
* [Mon_Ouie](http://github.com/mon-ouie)
|
394
|
+
* [injekt](http://github.com/injekt)
|
data/Rakefile
CHANGED
@@ -10,13 +10,13 @@ CLEAN.include("**/*#*", "**/*#*.*", "**/*_flymake*.*", "**/*_flymake",
|
|
10
10
|
|
11
11
|
def apply_spec_defaults(s)
|
12
12
|
s.name = "pry"
|
13
|
-
s.summary = "
|
13
|
+
s.summary = "An IRB alternative and runtime developer console"
|
14
14
|
s.version = Pry::VERSION
|
15
15
|
s.date = Time.now.strftime '%Y-%m-%d'
|
16
16
|
s.author = "John Mair (banisterfiend)"
|
17
17
|
s.email = 'jrmair@gmail.com'
|
18
18
|
s.description = s.summary
|
19
|
-
s.homepage = "http://
|
19
|
+
s.homepage = "http://pry.github.com"
|
20
20
|
s.executables = ["pry"]
|
21
21
|
s.files = `git ls-files`.split("\n")
|
22
22
|
s.test_files = `git ls-files -- test/*`.split("\n")
|
data/TODO
CHANGED
@@ -1,10 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
*
|
7
|
-
*
|
1
|
+
0.9.3
|
2
|
+
* hist command now excludes last line of input (the command invocation itself)
|
3
|
+
* hist now has `history` alias
|
4
|
+
* `pry -r` requires now happen after plugin loading (so as not to interfere with
|
5
|
+
* new Pry.config.disable_auto_reload option, for turning off auto reloading by edit-method and related
|
6
|
+
* add better error messages for `cd` command
|
7
|
+
* add command_prefix
|
8
|
+
* change some command names to include hyphen, e.g version => pry-version, install => install-command
|
9
|
+
* do cat --ex and edit --ex
|
10
|
+
* add reload-method
|
11
|
+
* fixed exotic object regression - BasicObject.new etc now return "=> unknown"
|
12
|
+
* converted: import => import-set, version => pry-version, install => install-command
|
13
|
+
* fix show-doc bug for ruby 1.8 and Kernel.fork
|
14
|
+
* edit -t (opens a temporary file and evals it in current context when closed)
|
8
15
|
|
9
16
|
0.9.0
|
10
17
|
Major features
|
data/bin/pry
CHANGED
data/lib/pry.rb
CHANGED
@@ -20,7 +20,11 @@ class Pry
|
|
20
20
|
|
21
21
|
# The default prints
|
22
22
|
DEFAULT_PRINT = proc do |output, value|
|
23
|
-
|
23
|
+
begin
|
24
|
+
Helpers::BaseHelpers.stagger_output("=> #{Helpers::BaseHelpers.colorize_code(value.pretty_inspect)}", output)
|
25
|
+
rescue NoMethodError
|
26
|
+
output.puts "=> unknown"
|
27
|
+
end
|
24
28
|
end
|
25
29
|
|
26
30
|
# Will only show the first line of the backtrace
|
@@ -49,7 +53,7 @@ class Pry
|
|
49
53
|
]
|
50
54
|
|
51
55
|
# A simple prompt - doesn't display target or nesting level
|
52
|
-
SIMPLE_PROMPT = [proc { ">> " }, proc { "
|
56
|
+
SIMPLE_PROMPT = [proc { ">> " }, proc { " | " }]
|
53
57
|
|
54
58
|
SHELL_PROMPT = [
|
55
59
|
proc { |target_self, _| "pry #{Pry.view_clip(target_self)}:#{Dir.pwd} $ " },
|
data/lib/pry/command_context.rb
CHANGED
@@ -11,6 +11,15 @@ class Pry
|
|
11
11
|
attr_accessor :command_set
|
12
12
|
attr_accessor :command_processor
|
13
13
|
|
14
|
+
# Run a command from another command.
|
15
|
+
# @param [String] command_string The string that invokes the command
|
16
|
+
# @param [Array] args Further arguments to pass to the command
|
17
|
+
# @example
|
18
|
+
# run "show-input"
|
19
|
+
# @example
|
20
|
+
# run ".ls"
|
21
|
+
# @example
|
22
|
+
# run "amend-line", "5", 'puts "hello world"'
|
14
23
|
def run(command_string, *args)
|
15
24
|
complete_string = "#{command_string} #{args.join(" ")}"
|
16
25
|
command_processor.process_commands(complete_string, eval_string, target)
|
@@ -55,7 +55,10 @@ class Pry
|
|
55
55
|
def command_matched(val, target)
|
56
56
|
_, cmd_data = commands.commands.find do |name, data|
|
57
57
|
|
58
|
-
|
58
|
+
prefix = Regexp.escape(Pry.config.command_prefix)
|
59
|
+
prefix = "(?:#{prefix})?" unless data.options[:use_prefix]
|
60
|
+
|
61
|
+
command_regex = /^#{prefix}#{convert_to_regex(name)}(?!\S)/
|
59
62
|
|
60
63
|
if data.options[:interpolate]
|
61
64
|
# If interpolation fails then the command cannot be matched,
|
data/lib/pry/command_set.rb
CHANGED
@@ -68,6 +68,9 @@ class Pry
|
|
68
68
|
# @option options [String] :listing The listing name of the
|
69
69
|
# command. That is the name by which the command is looked up by
|
70
70
|
# help and by show-command. Necessary for regex based commands.
|
71
|
+
# @option options [Boolean] :use_prefix Whether the command uses
|
72
|
+
# `Pry.config.command_prefix` prefix (if one is defined). Defaults
|
73
|
+
# to true.
|
71
74
|
# @yield The action to perform. The parameters in the block
|
72
75
|
# determines the parameters the command will receive. All
|
73
76
|
# parameters passed into the block will be strings. Successive
|
@@ -105,7 +108,8 @@ class Pry
|
|
105
108
|
:keep_retval => false,
|
106
109
|
:argument_required => false,
|
107
110
|
:interpolate => true,
|
108
|
-
:listing => name
|
111
|
+
:listing => name,
|
112
|
+
:use_prefix => true
|
109
113
|
}.merge!(options)
|
110
114
|
|
111
115
|
unless command_dependencies_met? options
|
@@ -115,7 +119,7 @@ class Pry
|
|
115
119
|
options[:stub_info] = proc do
|
116
120
|
output.puts "\nThe command '#{name}' is #{Helpers::Text.bold("unavailable")} because it requires the following gems to be installed: #{(gems_not_installed.join(", "))}"
|
117
121
|
output.puts "-"
|
118
|
-
output.puts "Type `install #{name}` to install the required gems and activate this command."
|
122
|
+
output.puts "Type `install-command #{name}` to install the required gems and activate this command."
|
119
123
|
end
|
120
124
|
end
|
121
125
|
|
@@ -123,7 +127,7 @@ class Pry
|
|
123
127
|
end
|
124
128
|
|
125
129
|
def each &block
|
126
|
-
@commands.each(&block)
|
130
|
+
@commands.each(&block)
|
127
131
|
end
|
128
132
|
|
129
133
|
# Removes some commands from the set
|
@@ -239,7 +243,7 @@ class Pry
|
|
239
243
|
end
|
240
244
|
end
|
241
245
|
|
242
|
-
command "install", "Install a disabled command." do |name|
|
246
|
+
command "install-command", "Install a disabled command." do |name|
|
243
247
|
command = find_command(name)
|
244
248
|
stub_info = command.options[:stub_info]
|
245
249
|
|
data/lib/pry/config.rb
CHANGED
@@ -57,6 +57,11 @@ class Pry
|
|
57
57
|
# @return [String, #call]
|
58
58
|
attr_accessor :editor
|
59
59
|
|
60
|
+
# A string that must precede all Pry commands (e.g., if command_prefix is
|
61
|
+
# set to "%", the "cd" command must be invoked as "%cd").
|
62
|
+
# @return [String]
|
63
|
+
attr_accessor :command_prefix
|
64
|
+
|
60
65
|
# @return [Boolean] Toggle Pry color on and off.
|
61
66
|
attr_accessor :color
|
62
67
|
|
@@ -71,6 +76,14 @@ class Pry
|
|
71
76
|
# @return [Boolean]
|
72
77
|
attr_accessor :should_load_plugins
|
73
78
|
|
79
|
+
# Determines whether to load files specified with the -r flag.
|
80
|
+
# @return [Boolean]
|
81
|
+
attr_accessor :should_load_requires
|
82
|
+
|
83
|
+
# Determines whether to disable edit-method's auto-reloading behavior.
|
84
|
+
# @return [Boolean]
|
85
|
+
attr_accessor :disable_auto_reload
|
86
|
+
|
74
87
|
# Config option for history.
|
75
88
|
# sub-options include hist.file, hist.load, and hist.save
|
76
89
|
# hist.file is the file to save/load history too, e.g
|
@@ -89,12 +102,11 @@ class Pry
|
|
89
102
|
# @return [OpenStruct]
|
90
103
|
attr_accessor :plugins
|
91
104
|
|
105
|
+
# @return [Array<String>] Ruby files to be required after loading any plugins.
|
106
|
+
attr_accessor :requires
|
107
|
+
|
92
108
|
# @return [Integer] Amount of results that will be stored into out
|
93
109
|
attr_accessor :memory_size
|
94
|
-
|
95
|
-
# @return [Boolean] Whether or not evalation results (`=>`) are sent
|
96
|
-
# through a pager.
|
97
|
-
attr_accessor :result_pager
|
98
110
|
end
|
99
111
|
end
|
100
112
|
|
@@ -16,17 +16,34 @@ class Pry
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
command "version", "Show Pry version." do
|
19
|
+
command "pry-version", "Show Pry version." do
|
20
20
|
output.puts "Pry version: #{Pry::VERSION} on Ruby #{RUBY_VERSION}."
|
21
21
|
end
|
22
22
|
|
23
|
-
command "import", "Import a command set" do |command_set_name|
|
23
|
+
command "import-set", "Import a command set" do |command_set_name|
|
24
24
|
next output.puts "Provide a command set name" if command_set.nil?
|
25
25
|
|
26
26
|
set = target.eval(arg_string)
|
27
27
|
Pry.active_instance.commands.import set
|
28
28
|
end
|
29
29
|
|
30
|
+
command "reload-method", "Reload the source file that contains the specified method" do |meth_name|
|
31
|
+
if (meth = get_method_object(meth_name, target, {})).nil?
|
32
|
+
output.puts "Invalid method name: #{meth_name}."
|
33
|
+
next
|
34
|
+
end
|
35
|
+
|
36
|
+
if is_a_c_method?(meth)
|
37
|
+
output.puts "Error: Can't reload a C method."
|
38
|
+
elsif is_a_dynamically_defined_method?(meth)
|
39
|
+
output.puts "Error: Can't reload an eval method."
|
40
|
+
else
|
41
|
+
file_name = meth.source_location.first
|
42
|
+
load file_name
|
43
|
+
output.puts "Reloaded #{file_name}."
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
30
47
|
command "reset", "Reset the REPL to a clean state." do
|
31
48
|
output.puts "Pry reset."
|
32
49
|
exec "pry"
|
@@ -3,7 +3,7 @@ class Pry
|
|
3
3
|
|
4
4
|
Input = Pry::CommandSet.new do
|
5
5
|
|
6
|
-
command "!", "Clear the input buffer. Useful if the parsing process goes wrong and you get stuck in the read loop." do
|
6
|
+
command "!", "Clear the input buffer. Useful if the parsing process goes wrong and you get stuck in the read loop.", :use_prefix => false do
|
7
7
|
output.puts "Input buffer cleared!"
|
8
8
|
eval_string.replace("")
|
9
9
|
end
|
@@ -56,11 +56,11 @@ e.g amend-line puts 'hello again' # no line number modifies immediately preced
|
|
56
56
|
|
57
57
|
command "play", "Play back a string or a method or a file as input. Type `play --help` for more information." do |*args|
|
58
58
|
opts = Slop.parse!(args) do |opt|
|
59
|
-
opt.banner "Usage: play [OPTIONS] [--help]\nDefault action (no options) is to play the provided string\ne.g `play puts 'hello world'` #=> \"hello world\"\ne.g `play -m Pry#repl --lines 1..-1`\ne.g `play -f Rakefile --lines 5
|
59
|
+
opt.banner "Usage: play [OPTIONS] [--help]\nDefault action (no options) is to play the provided string\ne.g `play puts 'hello world'` #=> \"hello world\"\ne.g `play -m Pry#repl --lines 1..-1`\ne.g `play -f Rakefile --lines 5`"
|
60
60
|
|
61
61
|
opt.on :l, :lines, 'The line (or range of lines) to replay.', true, :as => Range
|
62
62
|
opt.on :m, :method, 'Play a method.', true
|
63
|
-
opt.on :f, "file", 'The
|
63
|
+
opt.on :f, "file", 'The file to replay in context.', true
|
64
64
|
opt.on :o, "open", 'When used with the -m switch, it plays the entire method except the last line, leaving the method definition "open". `amend-line` can then be used to modify the method.'
|
65
65
|
opt.on :h, :help, "This message." do
|
66
66
|
output.puts opt
|
@@ -95,8 +95,9 @@ e.g amend-line puts 'hello again' # no line number modifies immediately preced
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
-
command "hist", "Show and replay Readline history. Type `hist --help` for more info." do |*args|
|
99
|
-
|
98
|
+
command "hist", "Show and replay Readline history. Type `hist --help` for more info. Aliases: history" do |*args|
|
99
|
+
# exclude the current command from history.
|
100
|
+
history = Readline::HISTORY.to_a[0..-2]
|
100
101
|
|
101
102
|
opts = Slop.parse!(args) do |opt|
|
102
103
|
opt.banner "Usage: hist [--replay START..END] [--clear] [--grep PATTERN] [--head N] [--tail N] [--help] [--save [START..END] file.txt]\n"
|
@@ -213,6 +214,7 @@ e.g amend-line puts 'hello again' # no line number modifies immediately preced
|
|
213
214
|
|
214
215
|
end
|
215
216
|
|
217
|
+
alias_command "history", "hist", ""
|
216
218
|
|
217
219
|
helpers do
|
218
220
|
def one_index_number(line_number)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
1
3
|
class Pry
|
2
4
|
module DefaultCommands
|
3
5
|
|
@@ -110,8 +112,10 @@ class Pry
|
|
110
112
|
"Ensure #{text.bold("Pry.editor")} is set to your editor of choice.\n" \
|
111
113
|
"e.g: edit sample.rb"
|
112
114
|
|
113
|
-
opt.on :r, "reload", "Eval file content after editing (
|
114
|
-
opt.on :
|
115
|
+
opt.on :r, "reload", "Eval file content after editing (evals at top level)"
|
116
|
+
opt.on :ex, "Open an editor at the line and file that generated the most recent Exception."
|
117
|
+
opt.on :t, "temp", "Open a temporary file in an editor and eval it in current context after closing."
|
118
|
+
opt.on :p, "play", "Use the pry `play` command to eval the file content after editing."
|
115
119
|
opt.on :l, "line", "Specify line number to jump to in file", true, :as => Integer
|
116
120
|
opt.on :h, :help, "This message." do
|
117
121
|
output.puts opt
|
@@ -119,19 +123,38 @@ class Pry
|
|
119
123
|
end
|
120
124
|
next if opts.h?
|
121
125
|
|
122
|
-
|
123
|
-
|
126
|
+
# the context the file will be eval'd in after closing
|
127
|
+
context = TOPLEVEL_BINDING
|
128
|
+
should_reload = opts[:r]
|
129
|
+
|
130
|
+
if opts.ex?
|
131
|
+
next output.puts "No Exception found." if Pry.last_exception.nil?
|
132
|
+
|
133
|
+
file_name = Pry.last_exception.file
|
134
|
+
line = Pry.last_exception.line
|
135
|
+
next output.puts "Exception has no associated file." if file_name.nil?
|
136
|
+
next output.puts "Cannot edit exceptions raised in REPL." if Pry.eval_path == file_name
|
137
|
+
elsif opts.t?
|
138
|
+
file_name = Tempfile.new("tmp").tap(&:close).path
|
139
|
+
line = 0
|
140
|
+
should_reload = true
|
141
|
+
context = target
|
142
|
+
else
|
143
|
+
next output.puts("Need to specify a file.") if !args.first
|
144
|
+
file_name = File.expand_path(args.first)
|
145
|
+
line = opts[:l].to_i
|
146
|
+
end
|
124
147
|
|
125
|
-
invoke_editor(file_name,
|
148
|
+
invoke_editor(file_name, line)
|
126
149
|
set_file_and_dir_locals(file_name)
|
127
150
|
|
128
|
-
if opts[:
|
151
|
+
if opts[:p]
|
129
152
|
silence_warnings do
|
130
|
-
|
153
|
+
Pry.active_instance.input = StringIO.new(File.readlines(file_name).join)
|
131
154
|
end
|
132
|
-
elsif
|
155
|
+
elsif should_reload
|
133
156
|
silence_warnings do
|
134
|
-
|
157
|
+
context.eval(File.read(file_name))
|
135
158
|
end
|
136
159
|
end
|
137
160
|
end
|
@@ -147,7 +170,7 @@ class Pry
|
|
147
170
|
|
148
171
|
opt.on :M, "instance-methods", "Operate on instance methods."
|
149
172
|
opt.on :m, :methods, "Operate on methods."
|
150
|
-
opt.on :n, "no-reload", "Do not automatically reload the method's file after
|
173
|
+
opt.on :n, "no-reload", "Do not automatically reload the method's file after editing."
|
151
174
|
opt.on "no-jump", "Do not fast forward editor to first line of method."
|
152
175
|
opt.on :c, :context, "Select object context to run under.", true do |context|
|
153
176
|
target = Pry.binding_for(target.eval(context))
|
@@ -179,7 +202,7 @@ class Pry
|
|
179
202
|
|
180
203
|
invoke_editor(file, opts["no-jump"] ? 0 : line)
|
181
204
|
silence_warnings do
|
182
|
-
load file if !opts.n?
|
205
|
+
load file if !opts.n? && !Pry.config.disable_auto_reload
|
183
206
|
end
|
184
207
|
end
|
185
208
|
end
|
@@ -197,7 +220,7 @@ class Pry
|
|
197
220
|
end
|
198
221
|
|
199
222
|
def start_line_syntax_for_editor(file_name, line_number)
|
200
|
-
file_name.gsub
|
223
|
+
file_name = file_name.gsub(/\//, '\\') if RUBY_PLATFORM =~ /mswin|mingw/
|
201
224
|
|
202
225
|
case Pry.editor
|
203
226
|
when /^[gm]?vi/, /^emacs/, /^nano/, /^pico/, /^gedit/, /^kate/
|
@@ -207,7 +230,7 @@ class Pry
|
|
207
230
|
when /^uedit32/
|
208
231
|
"#{file_name}/#{line_number}"
|
209
232
|
when /^jedit/
|
210
|
-
"#{file_name}
|
233
|
+
"#{file_name} +line:#{line_number}"
|
211
234
|
else
|
212
235
|
if RUBY_PLATFORM =~ /mswin|mingw/
|
213
236
|
"#{file_name}"
|
@@ -3,7 +3,7 @@ class Pry
|
|
3
3
|
|
4
4
|
Shell = Pry::CommandSet.new do
|
5
5
|
|
6
|
-
command(/\.(.*)/, "All text following a '.' is forwarded to the shell.", :listing => ".<shell command>") do |cmd|
|
6
|
+
command(/\.(.*)/, "All text following a '.' is forwarded to the shell.", :listing => ".<shell command>", :use_prefix => false) do |cmd|
|
7
7
|
if cmd =~ /^cd\s+(.+)/i
|
8
8
|
dest = $1
|
9
9
|
begin
|
@@ -37,6 +37,7 @@ class Pry
|
|
37
37
|
command "cat", "Show output of file FILE. Type `cat --help` for more information." do |*args|
|
38
38
|
start_line = 0
|
39
39
|
end_line = -1
|
40
|
+
file_name = nil
|
40
41
|
|
41
42
|
opts = Slop.parse!(args) do |opt|
|
42
43
|
opt.on :s, :start, "Start line (defaults to start of file)Line 1 is the first line.", true, :as => Integer do |line|
|
@@ -47,6 +48,16 @@ class Pry
|
|
47
48
|
end_line = line - 1
|
48
49
|
end
|
49
50
|
|
51
|
+
opt.on :ex, "Show a window of N lines around last exception (defaults to 5).", :optional => true, :as => Integer do |window_size|
|
52
|
+
window_size ||= 5
|
53
|
+
ex = Pry.last_exception
|
54
|
+
next if !ex
|
55
|
+
start_line = (ex.line - 1) - window_size
|
56
|
+
start_line = start_line < 0 ? 0 : start_line
|
57
|
+
end_line = (ex.line - 1) + window_size
|
58
|
+
file_name = ex.file
|
59
|
+
end
|
60
|
+
|
50
61
|
opt.on :l, "line-numbers", "Show line numbers."
|
51
62
|
opt.on :t, :type, "The specific file type for syntax higlighting (e.g ruby, python)", true, :as => Symbol
|
52
63
|
opt.on :f, :flood, "Do not use a pager to view text longer than one screen."
|
@@ -57,7 +68,13 @@ class Pry
|
|
57
68
|
|
58
69
|
next if opts.help?
|
59
70
|
|
60
|
-
|
71
|
+
if opts.ex?
|
72
|
+
next output.puts "No Exception or Exception has no associated file." if file_name.nil?
|
73
|
+
next output.puts "Cannot cat exceptions raised in REPL." if Pry.eval_path == file_name
|
74
|
+
else
|
75
|
+
file_name = args.shift
|
76
|
+
end
|
77
|
+
|
61
78
|
if !file_name
|
62
79
|
output.puts "Must provide a file name."
|
63
80
|
next
|
@@ -65,6 +82,18 @@ class Pry
|
|
65
82
|
|
66
83
|
contents, normalized_start_line, _ = read_between_the_lines(file_name, start_line, end_line)
|
67
84
|
|
85
|
+
# add the arrow pointing to line that caused the exception
|
86
|
+
if opts.ex?
|
87
|
+
contents = contents.lines.each_with_index.map do |line, idx|
|
88
|
+
l = idx + start_line
|
89
|
+
if l == (Pry.last_exception.line - 1)
|
90
|
+
"=> #{line}"
|
91
|
+
else
|
92
|
+
" #{line}"
|
93
|
+
end
|
94
|
+
end.join
|
95
|
+
end
|
96
|
+
|
68
97
|
if Pry.color
|
69
98
|
contents = syntax_highlight_by_file_type_or_specified(contents, file_name, opts[:type])
|
70
99
|
end
|
@@ -11,67 +11,6 @@ class Pry
|
|
11
11
|
|
12
12
|
meth.reload
|
13
13
|
end
|
14
|
-
|
15
|
-
command "blame", "Show blame for a method", :requires_gem => "grit" do |meth_name|
|
16
|
-
require 'grit'
|
17
|
-
if (meth = get_method_object(meth_name, target, {})).nil?
|
18
|
-
output.puts "Invalid method name: #{meth_name}."
|
19
|
-
next
|
20
|
-
end
|
21
|
-
|
22
|
-
repo ||= Grit::Repo.new(".")
|
23
|
-
start_line = meth.source_location.last
|
24
|
-
num_lines = meth.source.lines.count
|
25
|
-
authors = repo.blame(meth.source_location.first).lines.select do |v|
|
26
|
-
v.lineno >= start_line && v.lineno <= start_line + num_lines
|
27
|
-
end.map do |v|
|
28
|
-
v.commit.author.output(Time.new).split(/</).first.strip
|
29
|
-
end
|
30
|
-
|
31
|
-
lines_with_blame = []
|
32
|
-
meth.source.lines.zip(authors) { |line, author| lines_with_blame << ("#{author}".ljust(10) + colorize_code(line)) }
|
33
|
-
output.puts lines_with_blame.join
|
34
|
-
end
|
35
|
-
|
36
|
-
command "diff", "Show the diff for a method", :requires_gem => ["grit", "diffy"] do |meth_name|
|
37
|
-
require 'grit'
|
38
|
-
require 'diffy'
|
39
|
-
|
40
|
-
if (meth = get_method_object(meth_name, target, {})).nil?
|
41
|
-
output.puts "Invalid method name: #{meth_name}."
|
42
|
-
next
|
43
|
-
end
|
44
|
-
|
45
|
-
output.puts colorize_code(Diffy::Diff.new(method_code_from_head(meth), meth.source))
|
46
|
-
end
|
47
|
-
|
48
|
-
helpers do
|
49
|
-
def get_file_from_commit(path)
|
50
|
-
repo = Grit::Repo.new('.')
|
51
|
-
head = repo.commits.first
|
52
|
-
tree_names = path.split("/")
|
53
|
-
start_tree = head.tree
|
54
|
-
blob_name = tree_names.last
|
55
|
-
tree = tree_names[0..-2].inject(start_tree) { |a, v| a.trees.find { |t| t.basename == v } }
|
56
|
-
blob = tree.blobs.find { |v| v.basename == blob_name }
|
57
|
-
blob.data
|
58
|
-
end
|
59
|
-
|
60
|
-
def method_code_from_head(meth)
|
61
|
-
rel_path = relative_path(meth.source_location.first)
|
62
|
-
code = get_file_from_commit(rel_path)
|
63
|
-
start_line = meth.source_location.last
|
64
|
-
code_length = meth.source.lines.count
|
65
|
-
code.lines.to_a[(start_line - 1)...((start_line - 1) + code_length)].join
|
66
|
-
end
|
67
|
-
|
68
|
-
def relative_path(path)
|
69
|
-
path =~ /#{Regexp.escape(File.expand_path("."))}\/(.*)/
|
70
|
-
$1
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
14
|
end
|
76
15
|
end
|
77
16
|
end
|
data/lib/pry/plugins.rb
CHANGED
data/lib/pry/pry_class.rb
CHANGED
@@ -82,6 +82,13 @@ class Pry
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
+
# Load any Ruby files specified with the -r flag on the command line.
|
86
|
+
def self.load_requires
|
87
|
+
Pry.config.requires.each do |file|
|
88
|
+
require file
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
85
92
|
# Start a Pry REPL.
|
86
93
|
# This method also loads the files specified in `Pry::RC_FILES` the
|
87
94
|
# first time it is invoked.
|
@@ -97,6 +104,7 @@ class Pry
|
|
97
104
|
# multiple times per each new session (i.e in debugging)
|
98
105
|
load_rc if Pry.config.should_load_rc
|
99
106
|
load_plugins if Pry.config.plugins.enabled
|
107
|
+
load_requires if Pry.config.should_load_requires
|
100
108
|
load_history if Pry.config.history.should_load
|
101
109
|
|
102
110
|
@initial_session = false
|
@@ -190,11 +198,16 @@ class Pry
|
|
190
198
|
config.pager = true
|
191
199
|
config.editor = default_editor_for_platform
|
192
200
|
config.should_load_rc = true
|
201
|
+
config.disable_auto_reload = false
|
202
|
+
config.command_prefix = ""
|
193
203
|
|
194
204
|
config.plugins ||= OpenStruct.new
|
195
205
|
config.plugins.enabled = true
|
196
206
|
config.plugins.strict_loading = true
|
197
207
|
|
208
|
+
config.requires ||= []
|
209
|
+
config.should_load_requires = true
|
210
|
+
|
198
211
|
config.history ||= OpenStruct.new
|
199
212
|
config.history.should_save = true
|
200
213
|
config.history.should_load = true
|
@@ -247,7 +260,7 @@ class Pry
|
|
247
260
|
if target.is_a?(Binding)
|
248
261
|
target
|
249
262
|
else
|
250
|
-
if
|
263
|
+
if TOPLEVEL_BINDING.eval('self') == target
|
251
264
|
TOPLEVEL_BINDING
|
252
265
|
else
|
253
266
|
target.__binding__
|
data/lib/pry/version.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -74,12 +74,15 @@ end
|
|
74
74
|
|
75
75
|
class InputTester
|
76
76
|
def initialize(*actions)
|
77
|
+
if actions.last.is_a?(Hash) && actions.last.keys == [:history]
|
78
|
+
@hist = actions.pop[:history]
|
79
|
+
end
|
77
80
|
@orig_actions = actions.dup
|
78
81
|
@actions = actions
|
79
82
|
end
|
80
83
|
|
81
84
|
def readline(*)
|
82
|
-
@actions.shift
|
85
|
+
@actions.shift.tap{ |line| @hist << line if @hist }
|
83
86
|
end
|
84
87
|
|
85
88
|
def rewind
|
@@ -93,6 +93,57 @@ describe "Pry::CommandProcessor" do
|
|
93
93
|
pos.should == command.name.length
|
94
94
|
end
|
95
95
|
|
96
|
+
it 'should correctly match a command preceded by the command_prefix if one is defined' do
|
97
|
+
Pry.config.command_prefix = "%"
|
98
|
+
|
99
|
+
@pry.commands.command("test-command") {}
|
100
|
+
command, captures, pos = @command_processor.command_matched "%test-command hello", binding
|
101
|
+
|
102
|
+
command.name.should == "test-command"
|
103
|
+
captures.should == []
|
104
|
+
pos.should == "test-command".length + "%".length
|
105
|
+
|
106
|
+
Pry.config.command_prefix = ''
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should not match a command not preceded by the command_prefix if one is defined' do
|
110
|
+
Pry.config.command_prefix = "%"
|
111
|
+
|
112
|
+
@pry.commands.command("test-command") {}
|
113
|
+
command, captures, pos = @command_processor.command_matched "test-command hello", binding
|
114
|
+
|
115
|
+
command.should == nil
|
116
|
+
captures.should == nil
|
117
|
+
|
118
|
+
Pry.config.command_prefix = ''
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'should match a command preceded by the command_prefix when :use_prefix => false' do
|
122
|
+
Pry.config.command_prefix = "%"
|
123
|
+
|
124
|
+
@pry.commands.command("test-command", "", :use_prefix => false) {}
|
125
|
+
command, captures, pos = @command_processor.command_matched "%test-command hello", binding
|
126
|
+
|
127
|
+
command.name.should == "test-command"
|
128
|
+
captures.should == []
|
129
|
+
pos.should == "test-command".length + "%".length
|
130
|
+
|
131
|
+
Pry.config.command_prefix = ''
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'should match a command not preceded by the command_prefix when :use_prefix => false' do
|
135
|
+
Pry.config.command_prefix = "%"
|
136
|
+
|
137
|
+
@pry.commands.command("test-command", "", :use_prefix => false) {}
|
138
|
+
command, captures, pos = @command_processor.command_matched "test-command hello", binding
|
139
|
+
|
140
|
+
command.name.should == "test-command"
|
141
|
+
captures.should == []
|
142
|
+
pos.should == "test-command".length
|
143
|
+
|
144
|
+
Pry.config.command_prefix = ''
|
145
|
+
end
|
146
|
+
|
96
147
|
it 'should correctly match a regex command with spaces in its name' do
|
97
148
|
regex_command_name = /test\s+(.+)\s+command/
|
98
149
|
@pry.commands.command(regex_command_name) {}
|
@@ -201,5 +252,4 @@ describe "Pry::CommandProcessor" do
|
|
201
252
|
# you'll cause yourself incredible confusion
|
202
253
|
lambda { @command_processor.command_matched('boast #{c}', binding) }.should.not.raise NameError
|
203
254
|
end
|
204
|
-
|
205
255
|
end
|
@@ -211,7 +211,7 @@ describe "Pry::DefaultCommands::Input" do
|
|
211
211
|
@hist.push "hello"
|
212
212
|
@hist.push "world"
|
213
213
|
str_output = StringIO.new
|
214
|
-
redirect_pry_io(InputTester.new("hist", "exit-all"), str_output) do
|
214
|
+
redirect_pry_io(InputTester.new("hist", "exit-all", :history => @hist), str_output) do
|
215
215
|
pry
|
216
216
|
end
|
217
217
|
str_output.string.should =~ /hello\n.*world/
|
@@ -223,7 +223,7 @@ describe "Pry::DefaultCommands::Input" do
|
|
223
223
|
@hist.push ":bucket"
|
224
224
|
@hist.push ":ostrich"
|
225
225
|
str_output = StringIO.new
|
226
|
-
redirect_pry_io(InputTester.new("hist --replay -1", "exit-all"), str_output) do
|
226
|
+
redirect_pry_io(InputTester.new("hist --replay -1", "exit-all", :history => @hist), str_output) do
|
227
227
|
pry
|
228
228
|
end
|
229
229
|
str_output.string.should =~ /ostrich/
|
@@ -234,7 +234,7 @@ describe "Pry::DefaultCommands::Input" do
|
|
234
234
|
@hist.push ":hello"
|
235
235
|
@hist.push ":carl"
|
236
236
|
str_output = StringIO.new
|
237
|
-
redirect_pry_io(InputTester.new("hist --replay 0..2", "exit-all"), str_output) do
|
237
|
+
redirect_pry_io(InputTester.new("hist --replay 0..2", "exit-all", :history => @hist), str_output) do
|
238
238
|
pry
|
239
239
|
end
|
240
240
|
str_output.string.should =~ /:hello\n.*:carl/
|
@@ -253,21 +253,21 @@ describe "Pry::DefaultCommands::Input" do
|
|
253
253
|
@hist.push "place holder"
|
254
254
|
|
255
255
|
str_output = StringIO.new
|
256
|
-
redirect_pry_io(InputTester.new("hist --grep o", "exit-all"), str_output) do
|
256
|
+
redirect_pry_io(InputTester.new("hist --grep o", "exit-all", :history => @hist), str_output) do
|
257
257
|
pry
|
258
258
|
end
|
259
259
|
str_output.string.should =~ /\d:.*?box\n\d:.*?button\n\d:.*?orange/
|
260
260
|
|
261
261
|
# test more than one word in a regex match (def blah)
|
262
262
|
str_output = StringIO.new
|
263
|
-
redirect_pry_io(InputTester.new("hist --grep def blah", "exit-all"), str_output) do
|
263
|
+
redirect_pry_io(InputTester.new("hist --grep def blah", "exit-all", :history => @hist), str_output) do
|
264
264
|
pry
|
265
265
|
end
|
266
266
|
str_output.string.should =~ /def blah 1/
|
267
267
|
|
268
268
|
# test more than one word with leading white space in a regex match (def boink)
|
269
269
|
str_output = StringIO.new
|
270
|
-
redirect_pry_io(InputTester.new("hist --grep def boink", "exit-all"), str_output) do
|
270
|
+
redirect_pry_io(InputTester.new("hist --grep def boink", "exit-all", :history => @hist), str_output) do
|
271
271
|
pry
|
272
272
|
end
|
273
273
|
str_output.string.should =~ /def boink 2/
|
@@ -280,7 +280,7 @@ describe "Pry::DefaultCommands::Input" do
|
|
280
280
|
end
|
281
281
|
|
282
282
|
str_output = StringIO.new
|
283
|
-
redirect_pry_io(InputTester.new("hist --tail 3", "exit-all"), str_output) do
|
283
|
+
redirect_pry_io(InputTester.new("hist --tail 3", "exit-all", :history => @hist), str_output) do
|
284
284
|
pry
|
285
285
|
end
|
286
286
|
|
@@ -297,7 +297,7 @@ describe "Pry::DefaultCommands::Input" do
|
|
297
297
|
end
|
298
298
|
|
299
299
|
str_output = StringIO.new
|
300
|
-
redirect_pry_io(InputTester.new("hist --head 4", "exit-all"), str_output) do
|
300
|
+
redirect_pry_io(InputTester.new("hist --head 4", "exit-all", :history => @hist), str_output) do
|
301
301
|
pry
|
302
302
|
end
|
303
303
|
|
@@ -314,7 +314,7 @@ describe "Pry::DefaultCommands::Input" do
|
|
314
314
|
end
|
315
315
|
|
316
316
|
str_output = StringIO.new
|
317
|
-
redirect_pry_io(InputTester.new("hist --show 1..4", "exit-all"), str_output) do
|
317
|
+
redirect_pry_io(InputTester.new("hist --show 1..4", "exit-all", :history => @hist), str_output) do
|
318
318
|
pry
|
319
319
|
end
|
320
320
|
|
data/test/test_pry.rb
CHANGED
@@ -17,6 +17,36 @@ describe Pry do
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
if RUBY_VERSION =~ /1.9/
|
21
|
+
describe "Exotic object support" do
|
22
|
+
|
23
|
+
# regression test for exotic object support
|
24
|
+
it "Should not error when return value is a BasicObject instance" do
|
25
|
+
|
26
|
+
lambda do
|
27
|
+
redirect_pry_io(InputTester.new("BasicObject.new", "exit-all"), StringIO.new) do
|
28
|
+
Pry.start
|
29
|
+
end
|
30
|
+
end.should.not.raise NoMethodError
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
describe "Pry.binding_for" do
|
38
|
+
|
39
|
+
# regression test for burg's bug (see git history)
|
40
|
+
it "Should not error when object doesn't have a valid == method" do
|
41
|
+
o = Object.new
|
42
|
+
def o.==(other)
|
43
|
+
raise
|
44
|
+
end
|
45
|
+
|
46
|
+
lambda { Pry.binding_for(o) }.should.not.raise Exception
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
20
50
|
describe "open a Pry session on an object" do
|
21
51
|
describe "rep" do
|
22
52
|
before do
|
@@ -710,7 +740,7 @@ describe Pry do
|
|
710
740
|
|
711
741
|
klass.commands.keys.size.should == 3
|
712
742
|
klass.commands.keys.include?("help").should == true
|
713
|
-
klass.commands.keys.include?("install").should == true
|
743
|
+
klass.commands.keys.include?("install-command").should == true
|
714
744
|
klass.commands.keys.include?("h").should == true
|
715
745
|
end
|
716
746
|
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
version: 0.9.
|
4
|
+
prerelease: 5
|
5
|
+
version: 0.9.3pre1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- John Mair (banisterfiend)
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-07-27 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: ruby_parser
|
@@ -78,7 +78,7 @@ dependencies:
|
|
78
78
|
version: 1.0.1
|
79
79
|
type: :development
|
80
80
|
version_requirements: *id006
|
81
|
-
description:
|
81
|
+
description: An IRB alternative and runtime developer console
|
82
82
|
email: jrmair@gmail.com
|
83
83
|
executables:
|
84
84
|
- pry
|
@@ -153,7 +153,7 @@ files:
|
|
153
153
|
- test/testrc
|
154
154
|
- wiki/Customizing-pry.md
|
155
155
|
- wiki/Home.md
|
156
|
-
homepage: http://
|
156
|
+
homepage: http://pry.github.com
|
157
157
|
licenses: []
|
158
158
|
|
159
159
|
post_install_message:
|
@@ -170,16 +170,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
170
170
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
171
|
none: false
|
172
172
|
requirements:
|
173
|
-
- - "
|
173
|
+
- - ">"
|
174
174
|
- !ruby/object:Gem::Version
|
175
|
-
version:
|
175
|
+
version: 1.3.1
|
176
176
|
requirements: []
|
177
177
|
|
178
178
|
rubyforge_project:
|
179
179
|
rubygems_version: 1.7.2
|
180
180
|
signing_key:
|
181
181
|
specification_version: 3
|
182
|
-
summary:
|
182
|
+
summary: An IRB alternative and runtime developer console
|
183
183
|
test_files:
|
184
184
|
- test/helper.rb
|
185
185
|
- test/test_command_helpers.rb
|