pry 0.1.0 → 0.1.2

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/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ 8/12/2010 version 0.1.2
2
+ * now rescuing SyntaxError as well as Racc::Parser error in valid_expression?
1
3
  8/12/2010 version 0.1.0
2
4
  * release!
3
5
 
data/README.markdown CHANGED
@@ -3,7 +3,7 @@ Pry
3
3
 
4
4
  (C) John Mair (banisterfiend) 2010
5
5
 
6
- _attach an irb-like session to any object_
6
+ _attach an irb-like session to any object at runtime_
7
7
 
8
8
  Pry is a simple Ruby REPL that specializes in the interactive
9
9
  manipulation of objects during the running of a program.
@@ -17,7 +17,7 @@ example: prying on an object at runtime
17
17
 
18
18
  With the `Pry.into()` method we can pry (open an irb-like session) on
19
19
  an object. In the example below we open a Pry session for the `Test` class and execute a method and add
20
- an instance variable. The program is halted for the duration of the session.
20
+ an instance variable. The current thread is halted for the duration of the session.
21
21
 
22
22
  require 'pry'
23
23
 
@@ -73,19 +73,6 @@ an instance variable inside that class:
73
73
  Ending Pry session for Hello
74
74
  pry(main)> exit
75
75
  Ending Pry session for main
76
-
77
- # program resumes here
78
-
79
-
80
- example: Spawn a separate thread so you can use `Pry` to manipulate an
81
- object without halting the program.
82
- ---------------------------------------------------------------------------------------------------
83
-
84
- If we embed our `Pry.into` method inside its own thread we can examine
85
- and manipulate objects without halting the program.
86
-
87
- # Pry.into() without parameters opens up the top-level (main)
88
- Thread.new { Pry.into }
89
76
 
90
77
 
91
78
  Features and limitations
@@ -123,6 +110,38 @@ Limitations:
123
110
  hash literal syntax (this: syntax) or the 'stabby lambda' syntax
124
111
  (->).
125
112
 
113
+ Commands
114
+ -----------
115
+
116
+ The Pry API:
117
+
118
+ * `Pry.into()` and `Pry.start()` and `Pry.repl()` are all aliases of
119
+ oneanother. They all start a Read-Eval-Print-Loop on the object they
120
+ receive as a parameter. In the case of no parameter they operate on
121
+ top-level (main). They can receive any object or a `Binding`
122
+ object as parameter.
123
+ * If, for some reason you do not want to 'loop' then use `Pry.rep()`; it
124
+ only performs the Read-Eval-Print section of the REPL - it ends the
125
+ session after just one line of input. It takes the same parameters as
126
+ `Pry.repl()`
127
+ * Likewise `Pry.re()` only performs the Read-Eval section of the REPL,
128
+ it returns the result of the evaluation. It also takes the same parameters as `Pry.repl()`
129
+ * Similarly `Pry.r()` only performs the Read section of the REPL, only
130
+ returning the Ruby expression (as a string) or an Exception object in
131
+ case of error. It takes the same parameters as all the others.
132
+
133
+ Pry supports a few commands inside the session itself:
134
+
135
+ * Typing `!` on a line by itself will refresh the REPL - useful for
136
+ getting you out of a situation if the parsing process
137
+ goes wrong.
138
+ * `exit` or `quit` will end the current Pry session. Note that it will
139
+ not end any containing Pry sessions if the current session happens
140
+ to be nested.
141
+ * `#exit` or `#quit` will end the currently running program.
142
+ * You can type `Pry.into(obj)` to nest another Pry session within the
143
+ current one with `obj` as the receiver of the new session. Very useful
144
+ when exploring large or complicated runtime state.
126
145
 
127
146
  Contact
128
147
  -------
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ CLEAN.include("ext/**/*.#{dlext}", "ext/**/*.log", "ext/**/*.o",
12
12
 
13
13
  def apply_spec_defaults(s)
14
14
  s.name = "pry"
15
- s.summary = "attach an irb-like session to any object"
15
+ s.summary = "attach an irb-like session to any object at runtime"
16
16
  s.version = Pry::VERSION
17
17
  s.date = Time.now.strftime '%Y-%m-%d'
18
18
  s.author = "John Mair (banisterfiend)"
data/lib/pry.rb CHANGED
@@ -1,6 +1,12 @@
1
+ # (C) John Mair (banisterfiend) 2010
2
+ # MIT License
3
+
4
+ direc = File.dirname(__FILE__)
5
+
1
6
  require 'rubygems'
2
7
  require 'readline'
3
8
  require 'ruby_parser'
9
+ require "#{direc}/pry/version"
4
10
 
5
11
  module Pry
6
12
  class << self
@@ -12,22 +18,28 @@ module Pry
12
18
  @wait_prompt = proc { |v| "pry(#{v})* " }
13
19
  @session_start_msg = proc { |v| "Beginning Pry session for #{v}" }
14
20
  @session_end_msg = proc { |v| "Ending Pry session for #{v}" }
21
+
22
+ # useful for ending all Pry sessions currently active
23
+ @dead = false
15
24
 
16
25
  # loop
17
26
  def self.repl(target=TOPLEVEL_BINDING)
18
27
  if !target.is_a?(Binding)
19
28
  target = target.instance_eval { binding }
20
29
  end
21
-
22
- puts session_start_msg.call(target.eval('self'))
30
+
31
+ target_self = target.eval('self')
32
+ puts session_start_msg.call(target_self)
23
33
 
24
34
  loop do
25
- if catch(:pop) { rep(target) } == :return
26
- break target.eval('self')
35
+ if catch(:pop) { rep(target) } == :return || @dead
36
+ break
27
37
  end
28
38
  end
29
39
 
30
- puts session_end_msg.call(target.eval('self'))
40
+ puts session_end_msg.call(target_self)
41
+
42
+ target_self
31
43
  end
32
44
 
33
45
  class << self
@@ -93,9 +105,17 @@ module Pry
93
105
 
94
106
  def self.valid_expression?(code)
95
107
  RubyParser.new.parse(code)
96
- rescue Racc::ParseError
108
+ rescue Racc::ParseError, SyntaxError
97
109
  false
98
110
  else
99
111
  true
100
112
  end
113
+
114
+ def self.kill
115
+ @dead = true
116
+ end
117
+
118
+ def self.revive
119
+ @dead = false
120
+ end
101
121
  end
data/lib/pry/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pry
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - John Mair (banisterfiend)
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 2.0.5
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
- description: attach an irb-like session to any object
35
+ description: attach an irb-like session to any object at runtime
36
36
  email: jrmair@gmail.com
37
37
  executables: []
38
38
 
@@ -77,6 +77,6 @@ rubyforge_project:
77
77
  rubygems_version: 1.3.7
78
78
  signing_key:
79
79
  specification_version: 3
80
- summary: attach an irb-like session to any object
80
+ summary: attach an irb-like session to any object at runtime
81
81
  test_files: []
82
82