pry-remote-em 0.4.0 → 0.4.1
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/README.md +100 -18
- data/lib/pry-remote-em/client.rb +4 -1
- data/lib/pry-remote-em/server.rb +28 -0
- data/lib/pry-remote-em/version.rb +1 -1
- metadata +11 -10
data/README.md
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
[PryRemoteEm](https://rubygems.org/gems/pry-remote-em) enables you to
|
2
|
+
start instances of Pry in a running
|
3
|
+
[EventMachine](http://rubyeventmachine.com/) program and connect to
|
4
|
+
those Pry instances over a network or the Internet. Once connected you
|
5
|
+
can interact with the internal state of the program.
|
4
6
|
|
5
7
|
It's based off of [Mon-Ouie's](https://github.com/Mon-Ouie) [pry-remote](https://github.com/Mon-Ouie/pry-remote) for DRb.
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
9
|
+
It adds user authentication and SSL support along with tab-completion
|
10
|
+
and paging. It's compatble with MRI 1.9, or any other VM with support
|
11
|
+
for Fibers and EventMachine.
|
10
12
|
|
11
13
|
|
12
14
|
# Installation
|
@@ -78,23 +80,103 @@ You can then connect to the pry session using ``pry-remote-em``:
|
|
78
80
|
|
79
81
|
# Features
|
80
82
|
|
83
|
+
## Multiple Servers
|
84
|
+
|
85
|
+
It's easy to run more than one PryRemoteEm service on a single machine,
|
86
|
+
or even in the same process. When you start the service via
|
87
|
+
*#remote_pry_em*, just specify *:auto* as the port to use. The service
|
88
|
+
will automatically take the next free port from 6462.
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
require "pry-remote-em/server"
|
92
|
+
|
93
|
+
os = ObjectSpace.each_object
|
94
|
+
expose = []
|
95
|
+
while expose.length < 5
|
96
|
+
o = os.next
|
97
|
+
expose.push(o) unless o.frozen?
|
98
|
+
end
|
99
|
+
|
100
|
+
EM.run {
|
101
|
+
expose.each {|o| o.remote_pry_em('localhost', :auto) }
|
102
|
+
}
|
103
|
+
```
|
104
|
+
|
105
|
+
$ ruby test/auto-demo.rb
|
106
|
+
[pry-remote-em] listening for connections on pryem://localhost:6462/
|
107
|
+
[pry-remote-em] listening for connections on pryem://localhost:6463/
|
108
|
+
[pry-remote-em] listening for connections on pryem://localhost:6464/
|
109
|
+
[pry-remote-em] listening for connections on pryem://localhost:6465/
|
110
|
+
[pry-remote-em] listening for connections on pryem://localhost:6466/
|
111
|
+
|
112
|
+
```shell
|
113
|
+
$ pry-remote-em
|
114
|
+
[pry-remote-em] client connected to pryem://127.0.0.1:6462/
|
115
|
+
[pry-remote-em] remote is PryRemoteEm 0.4.0 pryem
|
116
|
+
[1] pry("pretty_print")>
|
117
|
+
|
118
|
+
$ pry-remote-em pryem://127.0.0.1:6463/
|
119
|
+
[pry-remote-em] client connected to pryem://127.0.0.1:6463/
|
120
|
+
[pry-remote-em] remote is PryRemoteEm 0.4.0 pryem
|
121
|
+
[1] pry("pack")>
|
122
|
+
|
123
|
+
$ pry-remote-em pryem://127.0.0.1:6464/
|
124
|
+
[pry-remote-em] client connected to pryem://127.0.0.1:6464/
|
125
|
+
[pry-remote-em] remote is PryRemoteEm 0.4.0 pryem
|
126
|
+
[1] pry("to_json")>
|
127
|
+
|
128
|
+
$ pry-remote-em pryem://127.0.0.1:6465/
|
129
|
+
[pry-remote-em] client connected to pryem://127.0.0.1:6465/
|
130
|
+
[pry-remote-em] remote is PryRemoteEm 0.4.0 pryem
|
131
|
+
[1] pry("to_json")>
|
132
|
+
|
133
|
+
$ pry-remote-em pryem://127.0.0.1:6466/
|
134
|
+
[pry-remote-em] client connected to pryem://127.0.0.1:6466/
|
135
|
+
[pry-remote-em] remote is PryRemoteEm 0.4.0 pryem
|
136
|
+
[1] pry(#<RubyVM::InstructionSequence>)>
|
137
|
+
```
|
138
|
+
|
81
139
|
## TLS Encryption
|
82
140
|
|
83
|
-
|
84
|
-
|
85
|
-
|
141
|
+
When creating a server pass the :tls => true option to enable TLS.
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
obj.remote_pry_em('localhost', :auto, :tls => true)
|
145
|
+
```
|
146
|
+
|
147
|
+
If you pass a Hash it will be used to configure the internal TLS handler.
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
obj.remote_pry_em('localhost', :auto, :tls => {:private_key_file => '/tmp/server.key'})
|
151
|
+
```
|
152
|
+
See [EventMachine::Connection#start_tls](http://eventmachine.rubyforge.org/EventMachine/Connection.html#M000296) for the available options.
|
153
|
+
|
154
|
+
|
155
|
+
When the command line client connects to a TLS enabled server it will
|
156
|
+
automatically use TLS mode even if the user didn't request it.
|
86
157
|
|
87
|
-
|
158
|
+
```bash
|
159
|
+
$ pry-remote-em pryem://localhost:6462/
|
160
|
+
[pry-remote-em] client connected to pryem://127.0.0.1:6462/
|
161
|
+
[pry-remote-em] remote is PryRemoteEm 0.4.0 pryems
|
162
|
+
[pry-remote-em] negotiating TLS
|
163
|
+
[pry-remote-em] TLS connection established
|
164
|
+
[1] pry(#<Hash>)>
|
165
|
+
```
|
166
|
+
|
167
|
+
To always require a TLS connection give pry-remote-em a pryem*s* URL. If
|
168
|
+
the server doesn't support TLS the connection will be terminated.
|
88
169
|
|
89
170
|
```bash
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
171
|
+
$ pry-remote-em pryems://localhost:6468/
|
172
|
+
[pry-remote-em] client connected to pryem://127.0.0.1:6468/
|
173
|
+
[pry-remote-em] remote is PryRemoteEm 0.4.0 pryem
|
174
|
+
[pry-remote-em] connection failed
|
175
|
+
[pry-remote-em] server doesn't support required scheme "pryems"
|
176
|
+
[pry-remote-em] session terminated
|
96
177
|
```
|
97
178
|
|
179
|
+
|
98
180
|
## User Authentication
|
99
181
|
|
100
182
|
### Server
|
@@ -114,9 +196,9 @@ EM.run{
|
|
114
196
|
|
115
197
|
#### Auth with a lambda
|
116
198
|
```ruby
|
117
|
-
require
|
199
|
+
require 'net/ldap'
|
118
200
|
ldap_anon = lambda do |user, pass|
|
119
|
-
ldap = Net::LDAP.new :host =>
|
201
|
+
ldap = Net::LDAP.new :host => '10.0.0.1', :port => 389, :auth => {:method => :simple, :username => user, :password => pass}
|
120
202
|
ldap.bind
|
121
203
|
end
|
122
204
|
obj = {:encoding => __ENCODING__, :weather => :cloudy}
|
data/lib/pry-remote-em/client.rb
CHANGED
@@ -55,7 +55,10 @@ module PryRemoteEm
|
|
55
55
|
def receive_json(j)
|
56
56
|
if j['p'] # prompt
|
57
57
|
if @negotiated && !@unbound
|
58
|
-
Fiber.new {
|
58
|
+
Fiber.new {
|
59
|
+
true while (l = Readline.readline(j['p'], true)).empty?
|
60
|
+
send_data(l)
|
61
|
+
}.resume
|
59
62
|
end
|
60
63
|
|
61
64
|
elsif j['d'] # printable data
|
data/lib/pry-remote-em/server.rb
CHANGED
@@ -1,5 +1,33 @@
|
|
1
1
|
require 'pry'
|
2
2
|
require 'pry-remote-em'
|
3
|
+
# How it works with Pry
|
4
|
+
#
|
5
|
+
# When PryRemoteEm.run is called it registers with EventMachine for a given ip
|
6
|
+
# and port. When a connection is received EM yields an instance of PryRemoteEm,
|
7
|
+
# we start a Fiber (f1) then call Pry.start specifying the Server instance as the
|
8
|
+
# input and output object for Pry. The Pry instance that is created goes into
|
9
|
+
# its REPL. When it gets to the read part it calls @input.readline
|
10
|
+
# (PryRemoteEm#readline) and passes a prompt, e.g., [1] pry(#<Foo>)>.
|
11
|
+
#
|
12
|
+
# PryRemoteEm#readline calls #send_data with the prompt then yields from the
|
13
|
+
# current Fiber (f1); the one we started when EventMachine yielded to us. The root
|
14
|
+
# Fiber is now active again. At some point, the root Fiber receives data from
|
15
|
+
# the client. It calls #receive_data in our Server instance. That instance then
|
16
|
+
# resumes the Fiber (f1) that was waiting for #readline to finish.
|
17
|
+
#
|
18
|
+
# Inside the resumed Fiber (f1) PryRemoteEm#readline returns the recieved data
|
19
|
+
# to the instance of Pry, which continues its REPL. Pry calls #puts, or #print
|
20
|
+
# or #write on its output object (PryRemoteEm). We send that data out to the client
|
21
|
+
# and immediately return. Pry then calls PryRemoteEm#readline again and again
|
22
|
+
# we send the prompt then immediately yield back to the root Fiber.
|
23
|
+
#
|
24
|
+
# Pry just interacts with PryRemoteEm as if it were any other blocking Readline
|
25
|
+
# object. The important bit is making sure that it is started in a new Fiber that
|
26
|
+
# can be paused and resumed as needed. PryRemoteEm#readline pauses it and
|
27
|
+
# PryRemoteEm#receive_json resumes it.
|
28
|
+
#
|
29
|
+
# Reference:
|
30
|
+
# http://www.igvita.com/2010/03/22/untangling-evented-code-with-ruby-fibers/
|
3
31
|
|
4
32
|
module PryRemoteEm
|
5
33
|
module Server
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pry-remote-em
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-31 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: eventmachine
|
16
|
-
requirement: &
|
16
|
+
requirement: &70255566066140 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70255566066140
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: pry
|
27
|
-
requirement: &
|
27
|
+
requirement: &70255566064780 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.9.6
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70255566064780
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rb-readline
|
38
|
-
requirement: &
|
38
|
+
requirement: &70255566063460 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70255566063460
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: highline
|
49
|
-
requirement: &
|
49
|
+
requirement: &70255566062900 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70255566062900
|
58
58
|
description: Connect to Pry remotely using EventMachine with tab-completion, paging,
|
59
59
|
user authentication and SSL support.
|
60
60
|
email: pry-remote-em@simulacre.org
|
@@ -95,3 +95,4 @@ signing_key:
|
|
95
95
|
specification_version: 3
|
96
96
|
summary: Connect to Pry remotely using EventMachine
|
97
97
|
test_files: []
|
98
|
+
has_rdoc:
|