pry 0.4.0 → 0.4.1pre1
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/.gemtest +0 -0
- data/README.markdown +12 -370
- data/Rakefile +2 -1
- data/lib/pry/command_base.rb +0 -1
- data/lib/pry/version.rb +1 -1
- metadata +31 -7
data/.gemtest
ADDED
File without changes
|
data/README.markdown
CHANGED
@@ -6,11 +6,20 @@ Pry
|
|
6
6
|
_attach an irb-like session to any object at runtime_
|
7
7
|
|
8
8
|
Pry is a simple Ruby REPL (Read-Eval-Print-Loop) that specializes in the interactive
|
9
|
-
manipulation of objects during the running of a program.
|
9
|
+
manipulation of objects during the running of a program.
|
10
|
+
|
11
|
+
In some sense it is the opposite of IRB in that you bring a REPL
|
12
|
+
session to your code (with Pry) instead of bringing your code to a
|
13
|
+
REPL session (as with IRB).
|
10
14
|
|
11
15
|
It is not based on the IRB codebase, and implements some unique REPL
|
12
16
|
commands such as `show_method` and `show_doc`
|
13
17
|
|
18
|
+
Pry is also fairly flexible and allows significant user
|
19
|
+
customization. It is trivial to set it to read from any
|
20
|
+
object that has a `readline` method and write to any object that has a
|
21
|
+
`puts` method - many other aspects of Pry are also configurable.
|
22
|
+
|
14
23
|
* Install the [gem](https://rubygems.org/gems/pry): `gem install pry`
|
15
24
|
* Read the [documentation](http://rdoc.info/github/banister/pry/master/file/README.markdown)
|
16
25
|
* See the [source code](http://github.com/banister/pry)
|
@@ -263,377 +272,10 @@ features, see the `examples/` directory.
|
|
263
272
|
Customizing Pry
|
264
273
|
---------------
|
265
274
|
|
266
|
-
Pry
|
267
|
-
the hooks, the prompt, and 'print' (the "P" in REPL).
|
268
|
-
|
269
|
-
Global customization, which applies to all Pry sessions, is done
|
270
|
-
through invoking class accessors on the `Pry` class, the accessors
|
271
|
-
are:
|
272
|
-
|
273
|
-
* `Pry.input=`
|
274
|
-
* `Pry.output=`
|
275
|
-
* `Pry.commands=`
|
276
|
-
* `Pry.hooks=`
|
277
|
-
* `Pry.prompt=`
|
278
|
-
* `Pry.print=`
|
279
|
-
|
280
|
-
Local customization (applied to a single Pry session) is done by
|
281
|
-
passing config hash options to `Pry.start()` or to `Pry.new()`; also the
|
282
|
-
same accessors as described above for the `Pry` class exist for a
|
283
|
-
Pry instance so that customization can occur during runtime.
|
284
|
-
|
285
|
-
### Input
|
286
|
-
|
287
|
-
For input Pry accepts any object that implements the `readline` method. This
|
288
|
-
includes `IO` objects, `StringIO`, `Readline` and custom objects. Pry
|
289
|
-
initially defaults to using `Readline` for input.
|
290
|
-
|
291
|
-
#### Example: Setting global input
|
292
|
-
|
293
|
-
Setting Pry's global input causes all subsequent Pry instances to use
|
294
|
-
this input by default:
|
295
|
-
|
296
|
-
Pry.input = StringIO.new("@x = 10\nexit")
|
297
|
-
Object.pry
|
298
|
-
|
299
|
-
Object.instance_variable_get(:@x) #=> 10
|
300
|
-
|
301
|
-
The above will execute the code in the `StringIO`
|
302
|
-
non-interactively. It gets all the input it needs from the `StringIO`
|
303
|
-
and then exits the Pry session. Note it is important to end the
|
304
|
-
session with 'exit' if you are running non-interactively or the Pry
|
305
|
-
session will hang as it loops indefinitely awaiting new input.
|
306
|
-
|
307
|
-
#### Example: Setting input for a specific session
|
308
|
-
|
309
|
-
The settings for a specific session override the global settings
|
310
|
-
(discussed above). There are two ways to set input for a specific pry session: At the
|
311
|
-
point the session is started, or within the session itself (at runtime):
|
312
|
-
|
313
|
-
##### At session start
|
314
|
-
|
315
|
-
Pry.start(Object, :input => StringIO.new("@x = 10\nexit"))
|
316
|
-
Object.instance_variable_get(:@x) #=> 10
|
317
|
-
|
318
|
-
##### At runtime
|
319
|
-
|
320
|
-
If you want to set the input object within the session itself you use
|
321
|
-
the special `_pry_` local variable which represents the Pry instance
|
322
|
-
managing the current session; inside the session we type:
|
323
|
-
|
324
|
-
_pry_.input = StringIO.new("@x = 10\nexit")
|
325
|
-
|
326
|
-
Note we can also set the input object for the parent Pry session (if
|
327
|
-
the current session is nested) like so:
|
328
|
-
|
329
|
-
_pry_.parent.input = StringIO.new("@x = 10\nexit")
|
330
|
-
|
331
|
-
### Output
|
332
|
-
|
333
|
-
For output Pry accepts any object that implements the `puts` method. This
|
334
|
-
includes `IO` objects, `StringIO` and custom objects. Pry initially
|
335
|
-
defaults to using `$stdout` for output.
|
336
|
-
|
337
|
-
#### Example: Setting global output
|
338
|
-
|
339
|
-
Setting Pry's global output causes all subsequent Pry instances to use
|
340
|
-
this output by default:
|
341
|
-
|
342
|
-
Pry.output = StringIO.new
|
343
|
-
|
344
|
-
#### Example: Setting output for a specific session
|
345
|
-
|
346
|
-
As per Input, given above, we set the local output as follows:
|
347
|
-
|
348
|
-
##### At session start
|
349
|
-
|
350
|
-
Pry.start(Object, :output => StringIO.new("@x = 10\nexit"))
|
351
|
-
|
352
|
-
##### At runtime
|
353
|
-
|
354
|
-
_pry_.output = StringIO.new
|
355
|
-
|
356
|
-
### Commands
|
357
|
-
|
358
|
-
Pry commands are not methods; they are commands that are intercepted
|
359
|
-
and executed before a Ruby eval takes place. Pry comes with a default
|
360
|
-
command set (`Pry::Commands`), but these commands can be augmented or overriden by
|
361
|
-
user-specified ones.
|
362
|
-
|
363
|
-
The Pry command API is quite sophisticated supporting features such as:
|
364
|
-
command set inheritance, importing of specific commands from another
|
365
|
-
command set, deletion of commands, calling of commands within other
|
366
|
-
commands, and so on.
|
367
|
-
|
368
|
-
A valid Pry command object must inherit from
|
369
|
-
`Pry::CommandBase` (or one of its subclasses) and use the special command API:
|
370
|
-
|
371
|
-
#### Example: Defining a command object and setting it globally
|
372
|
-
|
373
|
-
class MyCommands < Pry::CommandBase
|
374
|
-
command "greet", "Greet the user." do |name|
|
375
|
-
output.puts "Hello #{name.capitalize}, how are you?"
|
376
|
-
end
|
377
|
-
end
|
378
|
-
|
379
|
-
Pry.commands = MyCommands
|
380
|
-
|
381
|
-
Then inside a pry session:
|
382
|
-
|
383
|
-
pry(main)> greet john
|
384
|
-
hello John, how are you?
|
385
|
-
=> nil
|
386
|
-
|
387
|
-
#### Example: Using a command object in a specific session
|
388
|
-
|
389
|
-
As in the case of `input` and `output`:
|
390
|
-
|
391
|
-
##### At session start:
|
392
|
-
|
393
|
-
Pry.start(self, :commands => MyCommands)
|
394
|
-
|
395
|
-
##### At runtime:
|
396
|
-
|
397
|
-
_pry_.commands = MyCommands
|
398
|
-
|
399
|
-
#### The command API
|
400
|
-
|
401
|
-
The command API is defined by the `Pry::CommandBase` class (hence why
|
402
|
-
all commands must inherit from it or a subclass). The API works as follows:
|
403
|
-
|
404
|
-
##### `command` method
|
405
|
-
|
406
|
-
The `command` method defines a new command, its parameter is the
|
407
|
-
name of the command and an optional second parameter is a description of
|
408
|
-
the command.
|
409
|
-
|
410
|
-
The associated block defines the action to be performed. The number of
|
411
|
-
parameters in the block determine the number of parameters that will
|
412
|
-
be sent to the command (from the Pry prompt) when it is invoked. Note
|
413
|
-
that all parameters that are received will be strings; if a parameter
|
414
|
-
is not received it will be set to `nil`.
|
415
|
-
|
416
|
-
command "hello" do |x, y, z|
|
417
|
-
puts "hello there #{x}, #{y}, and #{z}!"
|
418
|
-
end
|
419
|
-
|
420
|
-
Command aliases can also be defined - simply use an array of strings
|
421
|
-
for the command name - all these strings will be valid names for the
|
422
|
-
command.
|
423
|
-
|
424
|
-
command ["ls", "dir"], "show a list of local vars" do
|
425
|
-
output.puts target.eval("local_variables")
|
426
|
-
end
|
427
|
-
|
428
|
-
##### `delete` method
|
429
|
-
|
430
|
-
The `delete` method deletes a command or a group of a commands; it
|
431
|
-
can be useful when inheriting from another command set when you decide
|
432
|
-
to keep only a portion of inherited commands.
|
433
|
-
|
434
|
-
class MyCommands < Pry::Commands
|
435
|
-
delete "show_method", "show_imethod"
|
436
|
-
end
|
437
|
-
|
438
|
-
##### `import_from` method
|
439
|
-
|
440
|
-
The `import_from` method enables you to specifically select which
|
441
|
-
commands will be copied across from another command set, useful when
|
442
|
-
you only want a small number of commands and so inheriting and then
|
443
|
-
deleting would be inefficient. The first parameter to `import_from`
|
444
|
-
is the class to import from and the other paramters are the names of
|
445
|
-
the commands to import:
|
446
|
-
|
447
|
-
class MyCommands < Pry::CommandBase
|
448
|
-
import_from Pry::Commands, "ls", "status", "!"
|
449
|
-
end
|
450
|
-
|
451
|
-
##### `run` method
|
452
|
-
|
453
|
-
The `run` command invokes one command from within another.
|
454
|
-
The first parameter is the name of the command to invoke
|
455
|
-
and the remainder of the parameters will be passed on to the command
|
456
|
-
being invoked:
|
457
|
-
|
458
|
-
class MyCommands < Pry::Commands
|
459
|
-
command "ls_with_hello" do
|
460
|
-
output.puts "hello!"
|
461
|
-
run "ls"
|
462
|
-
end
|
463
|
-
end
|
464
|
-
|
465
|
-
#### Utility methods for commands
|
466
|
-
|
467
|
-
All commands can access the special `output` and `target` methods. The
|
468
|
-
`output` method returns the `output` object for the active pry session.
|
469
|
-
Ensuring that your commands invoke `puts` on this rather than using
|
470
|
-
the top-level `puts` will ensure that all your session output goes to
|
471
|
-
the same place.
|
472
|
-
|
473
|
-
The `target` method returns the `Binding` object the Pry session is currently
|
474
|
-
active on - useful when your commands need to manipulate or examine
|
475
|
-
the state of the object. E.g, the "ls" command is implemented as follows
|
476
|
-
|
477
|
-
command "ls" do
|
478
|
-
output.puts target.eval("local_variables + instance_variables").inspect
|
479
|
-
end
|
480
|
-
|
481
|
-
#### The opts hash
|
482
|
-
|
483
|
-
These are miscellaneous variables that may be useful to your commands:
|
484
|
-
|
485
|
-
* `opts[:val]` - The line of input that invoked the command.
|
486
|
-
* `opts[:eval_string]` - The cumulative lines of input for multi-line input.
|
487
|
-
* `opts[:nesting]` - Lowlevel session nesting information.
|
488
|
-
* `opts[:commands]` - Lowlevel data of all Pry commands.
|
489
|
-
|
490
|
-
(see commands.rb for examples of how some of these options are used)
|
491
|
-
|
492
|
-
#### The `help` command
|
493
|
-
|
494
|
-
The `Pry::CommandBase` class automatically defines a `help` command
|
495
|
-
for you. Typing `help` in a Pry session will show a list of commands
|
496
|
-
to the user followed by their descriptions. Passing a parameter to
|
497
|
-
`help` with the command name will just return the description of that
|
498
|
-
specific command. If a description is left out it will automatically
|
499
|
-
be given the description "No description.".
|
500
|
-
|
501
|
-
If the description is explicitly set to `""` then this command will
|
502
|
-
not be displayed in `help`.
|
503
|
-
|
504
|
-
### Hooks
|
505
|
-
|
506
|
-
Currently Pry supports just two hooks: `before_session` and
|
507
|
-
`after_session`. These hooks are invoked before a Pry session starts
|
508
|
-
and after a session ends respectively. The default hooks used are
|
509
|
-
stored in the `Pry::DEFAULT_HOOKS` and just output the text `"Beginning
|
510
|
-
Pry session for <obj>"` and `"Ending Pry session for <obj>"`.
|
511
|
-
|
512
|
-
#### Example: Setting global hooks
|
513
|
-
|
514
|
-
All subsequent Pry instances will use these hooks as default:
|
515
|
-
|
516
|
-
Pry.hooks = {
|
517
|
-
:before_session => proc { |out, obj| out.puts "Opened #{obj}" },
|
518
|
-
:after_session => proc { |out, obj| out.puts "Closed #{obj}" }
|
519
|
-
}
|
520
|
-
|
521
|
-
5.pry
|
522
|
-
|
523
|
-
Inside the session:
|
524
|
-
|
525
|
-
Opened 5
|
526
|
-
pry(5)> exit
|
527
|
-
Closed 5
|
528
|
-
|
529
|
-
Note that the `before_session` and `after_session` procs receive the
|
530
|
-
current session's output object and session receiver as parameters.
|
531
|
-
|
532
|
-
#### Example: Setting hooks for a specific session
|
533
|
-
|
534
|
-
Like all the other customization options, the global default (as
|
535
|
-
explained above) can be overriden for a specific session, either at
|
536
|
-
session start or during runtime.
|
537
|
-
|
538
|
-
##### At session start
|
539
|
-
|
540
|
-
Pry.start(self, :hooks => { :before_session => proc { puts "hello world!" },
|
541
|
-
:after_session => proc { puts "goodbye world!" }
|
542
|
-
})
|
543
|
-
|
544
|
-
##### At runtime
|
545
|
-
|
546
|
-
_pry_.hooks = { :before_session => proc { puts "puts "hello world!" } }
|
547
|
-
|
548
|
-
### Prompts
|
549
|
-
|
550
|
-
The Pry prompt is used by `Readline` and other input objects that
|
551
|
-
accept a prompt. Pry can accept two prompt-types for every prompt; the
|
552
|
-
'main prompt' and the 'wait prompt'. The main prompt is always used
|
553
|
-
for the first line of input; the wait prompt is used in multi-line
|
554
|
-
input to indicate that the current expression is incomplete and more lines of
|
555
|
-
input are required. The default Prompt used by Pry is stored in the
|
556
|
-
`Pry::DEFAULT_PROMPT` constant.
|
557
|
-
|
558
|
-
A valid Pry prompt is either a single `Proc` object or a two element
|
559
|
-
array of `Proc` objects. When an array is used the first element is
|
560
|
-
the 'main prompt' and the last element is the 'wait prompt'. When a
|
561
|
-
single `Proc` object is used it will be used for both the main prompt
|
562
|
-
and the wait prompt.
|
563
|
-
|
564
|
-
#### Example: Setting global prompt
|
565
|
-
|
566
|
-
The prompt `Proc` objects are passed the receiver of the Pry session
|
567
|
-
and the nesting level of that session as parameters (they can simply
|
568
|
-
ignore these if they do not need them).
|
569
|
-
|
570
|
-
# Using one proc for both main and wait prompts
|
571
|
-
Pry.prompt = proc { |obj, nest_level| "#{obj}:#{nest_level}> " }
|
572
|
-
|
573
|
-
# Alternatively, provide two procs; one for main and one for wait
|
574
|
-
Pry.prompt = [ proc { "ENTER INPUT> " }, proc { "MORE INPUT REQUIRED!* " }]
|
575
|
-
|
576
|
-
#### Example: Setting the prompt for a specific session
|
577
|
-
|
578
|
-
##### At session start
|
579
|
-
|
580
|
-
Pry.start(self, :prompt => [proc { "ENTER INPUT> " },
|
581
|
-
proc { "MORE INPUT REQUIRED!* " }])
|
582
|
-
|
583
|
-
##### At runtime
|
584
|
-
|
585
|
-
_pry_.prompt = [proc { "ENTER INPUT> " },
|
586
|
-
proc { "MORE INPUT REQUIRED!* " }]
|
587
|
-
|
588
|
-
### Print
|
589
|
-
|
590
|
-
The Print phase of Pry's READ-EVAL-PRINT-LOOP can be customized. The
|
591
|
-
default action is stored in the `Pry::DEFAULT_PRINT` constant and it
|
592
|
-
simply outputs the value of the current expression preceded by a `=>` (or the first
|
593
|
-
line of the backtrace if the value is an `Exception` object.)
|
594
|
-
|
595
|
-
The print object should be a `Proc` and the parameters passed to the
|
596
|
-
`Proc` are the output object for the current session and the 'value'
|
597
|
-
returned by the current expression.
|
598
|
-
|
599
|
-
#### Example: Setting global print object
|
600
|
-
|
601
|
-
Let's define a print object that displays the full backtrace of any
|
602
|
-
exception and precedes the output of a value by the text `"Output is: "`:
|
603
|
-
|
604
|
-
Pry.print = proc do |output, value|
|
605
|
-
case value
|
606
|
-
when Exception
|
607
|
-
output.puts value.backtrace
|
608
|
-
else
|
609
|
-
output.puts "Output is: #{value}"
|
610
|
-
end
|
611
|
-
end
|
612
|
-
|
613
|
-
#### Example: Setting the print object for a specific session
|
614
|
-
|
615
|
-
##### At session start
|
616
|
-
|
617
|
-
Pry.start(self, :print => proc do |output, value|
|
618
|
-
case value
|
619
|
-
when Exception
|
620
|
-
output.puts value.backtrace
|
621
|
-
else
|
622
|
-
output.puts "Output is: #{value.inspect}"
|
623
|
-
end
|
624
|
-
end)
|
275
|
+
Pry allows a large degree of customization.
|
625
276
|
|
626
|
-
|
277
|
+
[Read how to customize Pry here.](http://rdoc.info/github/banister/pry/master/file/wiki/Customizing-pry.md)
|
627
278
|
|
628
|
-
_pry_.print = proc do |output, value|
|
629
|
-
case value
|
630
|
-
when Exception
|
631
|
-
output.puts value.backtrace
|
632
|
-
else
|
633
|
-
output.puts "Output is: #{value.inspect}"
|
634
|
-
end
|
635
|
-
end
|
636
|
-
|
637
279
|
Contact
|
638
280
|
-------
|
639
281
|
|
data/Rakefile
CHANGED
@@ -21,10 +21,11 @@ def apply_spec_defaults(s)
|
|
21
21
|
s.require_path = 'lib'
|
22
22
|
s.add_dependency("ruby_parser",">=2.0.5")
|
23
23
|
s.add_dependency("method_source",">=0.2.0")
|
24
|
+
s.add_development_dependency("bacon",">=1.1.0")
|
24
25
|
s.homepage = "http://banisterfiend.wordpress.com"
|
25
26
|
s.has_rdoc = 'yard'
|
26
27
|
s.files = Dir["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c", "lib/**/*.rb",
|
27
|
-
"test/*.rb", "CHANGELOG", "README.markdown", "Rakefile"]
|
28
|
+
"test/*.rb", "CHANGELOG", "README.markdown", "Rakefile", ".gemtest"]
|
28
29
|
end
|
29
30
|
|
30
31
|
task :test do
|
data/lib/pry/command_base.rb
CHANGED
data/lib/pry/version.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 274698070
|
5
|
+
prerelease: true
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 4
|
8
|
-
-
|
9
|
-
version: 0.4.
|
9
|
+
- 1pre1
|
10
|
+
version: 0.4.1pre1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- John Mair (banisterfiend)
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2011-01-
|
18
|
+
date: 2011-01-24 00:00:00 +13:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
@@ -25,6 +26,7 @@ dependencies:
|
|
25
26
|
requirements:
|
26
27
|
- - ">="
|
27
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 5
|
28
30
|
segments:
|
29
31
|
- 2
|
30
32
|
- 0
|
@@ -40,6 +42,7 @@ dependencies:
|
|
40
42
|
requirements:
|
41
43
|
- - ">="
|
42
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 23
|
43
46
|
segments:
|
44
47
|
- 0
|
45
48
|
- 2
|
@@ -47,6 +50,22 @@ dependencies:
|
|
47
50
|
version: 0.2.0
|
48
51
|
type: :runtime
|
49
52
|
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: bacon
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 19
|
62
|
+
segments:
|
63
|
+
- 1
|
64
|
+
- 1
|
65
|
+
- 0
|
66
|
+
version: 1.1.0
|
67
|
+
type: :development
|
68
|
+
version_requirements: *id003
|
50
69
|
description: attach an irb-like session to any object at runtime
|
51
70
|
email: jrmair@gmail.com
|
52
71
|
executables: []
|
@@ -72,6 +91,7 @@ files:
|
|
72
91
|
- CHANGELOG
|
73
92
|
- README.markdown
|
74
93
|
- Rakefile
|
94
|
+
- .gemtest
|
75
95
|
has_rdoc: yard
|
76
96
|
homepage: http://banisterfiend.wordpress.com
|
77
97
|
licenses: []
|
@@ -86,17 +106,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
106
|
requirements:
|
87
107
|
- - ">="
|
88
108
|
- !ruby/object:Gem::Version
|
109
|
+
hash: 3
|
89
110
|
segments:
|
90
111
|
- 0
|
91
112
|
version: "0"
|
92
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
114
|
none: false
|
94
115
|
requirements:
|
95
|
-
- - "
|
116
|
+
- - ">"
|
96
117
|
- !ruby/object:Gem::Version
|
118
|
+
hash: 25
|
97
119
|
segments:
|
98
|
-
-
|
99
|
-
|
120
|
+
- 1
|
121
|
+
- 3
|
122
|
+
- 1
|
123
|
+
version: 1.3.1
|
100
124
|
requirements: []
|
101
125
|
|
102
126
|
rubyforge_project:
|