pry-remote 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pry-remote.rb +84 -55
- metadata +34 -40
data/lib/pry-remote.rb
CHANGED
@@ -5,6 +5,9 @@ require 'readline'
|
|
5
5
|
require 'open3'
|
6
6
|
|
7
7
|
module PryRemote
|
8
|
+
DefaultHost = "localhost"
|
9
|
+
DefaultPort = 9876
|
10
|
+
|
8
11
|
# A class to represent an input object created from DRb. This is used because
|
9
12
|
# Pry checks for arity to know if a prompt should be passed to the object.
|
10
13
|
#
|
@@ -23,8 +26,6 @@ module PryRemote
|
|
23
26
|
stdin.close # Send EOF to the process
|
24
27
|
|
25
28
|
until stdout.eof? and stderr.eof?
|
26
|
-
ios = [stdout, stderr]
|
27
|
-
|
28
29
|
if res = IO.select([stdout, stderr])
|
29
30
|
res[0].each do |io|
|
30
31
|
next if io.eof?
|
@@ -59,16 +60,91 @@ module PryRemote
|
|
59
60
|
end
|
60
61
|
end
|
61
62
|
|
63
|
+
class Server
|
64
|
+
def self.run(object, host = DefaultHost, port = DefaultPort)
|
65
|
+
new(object, host, port).run
|
66
|
+
end
|
67
|
+
|
68
|
+
def initialize(object, host = "loclahost", port = DefaultPort)
|
69
|
+
@uri = "druby://#{host}:#{port}"
|
70
|
+
@object = object
|
71
|
+
|
72
|
+
@client = PryRemote::Client.new
|
73
|
+
DRb.start_service @uri, @client
|
74
|
+
|
75
|
+
puts "[pry-remote] Waiting for client on #@uri"
|
76
|
+
@client.wait
|
77
|
+
|
78
|
+
puts "[pry-remote] Client received, starting remote sesion"
|
79
|
+
end
|
80
|
+
|
81
|
+
# Code that has to be called for Pry-remote to work properly
|
82
|
+
def setup
|
83
|
+
# If client passed stdout and stderr, redirect actual messages there.
|
84
|
+
@old_stdout, $stdout = if @client.stdout
|
85
|
+
[$stdout, @client.stdout]
|
86
|
+
else
|
87
|
+
[$stdout, $stdout]
|
88
|
+
end
|
89
|
+
|
90
|
+
@old_stderr, $stderr = if @client.stderr
|
91
|
+
[$stderr, @client.stderr]
|
92
|
+
else
|
93
|
+
[$stderr, $stderr]
|
94
|
+
end
|
95
|
+
|
96
|
+
# Before Pry starts, save the pager config.
|
97
|
+
# We want to disable this because the pager won't do anything useful in
|
98
|
+
# this case (it will run on the server).
|
99
|
+
Pry.config.pager, @old_pager = false, Pry.config.pager
|
100
|
+
|
101
|
+
# As above, but for system config
|
102
|
+
Pry.config.system, @old_system = PryRemote::System, Pry.config.system
|
103
|
+
end
|
104
|
+
|
105
|
+
# Code that has to be called after setup to return to the initial state
|
106
|
+
def teardown
|
107
|
+
# Reset output streams
|
108
|
+
$stdout = @old_stdout
|
109
|
+
$stderr = @old_stderr
|
110
|
+
|
111
|
+
# Reset config
|
112
|
+
Pry.config.pager = @old_pager
|
113
|
+
|
114
|
+
# Reset sysem
|
115
|
+
Pry.config.system = @old_system
|
116
|
+
|
117
|
+
puts "[pry-remote] Remote sesion terminated"
|
118
|
+
@client.kill
|
119
|
+
|
120
|
+
DRb.stop_service
|
121
|
+
end
|
122
|
+
|
123
|
+
# Actually runs pry-remote
|
124
|
+
def run
|
125
|
+
setup
|
126
|
+
Pry.start(@object, :input => client.input_proxy, :output => client.output)
|
127
|
+
ensure
|
128
|
+
teardown
|
129
|
+
end
|
130
|
+
|
131
|
+
# @return Object to enter into
|
132
|
+
attr_reader :object
|
133
|
+
|
134
|
+
# @return [PryServer::Client] Client connecting to the pry-remote server
|
135
|
+
attr_reader :client
|
136
|
+
end
|
137
|
+
|
62
138
|
# Parses arguments and allows to start the client.
|
63
139
|
class CLI
|
64
140
|
def initialize(args = ARGV)
|
65
141
|
params = Slop.parse args, :help => true do
|
66
142
|
banner "#$PROGRAM_NAME [OPTIONS]"
|
67
143
|
|
68
|
-
on :h, :host, "Host of the server (
|
69
|
-
:default =>
|
70
|
-
on :p, :port, "Port of the server (
|
71
|
-
:default =>
|
144
|
+
on :h, :host, "Host of the server (#{DefaultHost})", true,
|
145
|
+
:default => DefaultHost
|
146
|
+
on :p, :port, "Port of the server (#{DefaultPort})", true,
|
147
|
+
:as => Integer, :default => DefaultPort
|
72
148
|
on :c, :capture, "Captures $stdout and $stderr from the server (true)",
|
73
149
|
:default => true
|
74
150
|
end
|
@@ -128,55 +204,8 @@ class Object
|
|
128
204
|
#
|
129
205
|
# @param [String] host Host of the server
|
130
206
|
# @param [Integer] port Port of the server
|
131
|
-
def remote_pry(host =
|
132
|
-
|
133
|
-
|
134
|
-
client = PryRemote::Client.new
|
135
|
-
DRb.start_service uri, client
|
136
|
-
|
137
|
-
puts "[pry-remote] Waiting for client on #{uri}"
|
138
|
-
client.wait
|
139
|
-
|
140
|
-
begin
|
141
|
-
# If client passed stdout and stderr, redirect actual messages there.
|
142
|
-
old_stdout, $stdout = if client.stdout
|
143
|
-
[$stdout, client.stdout]
|
144
|
-
else
|
145
|
-
[$stdout, $stdout]
|
146
|
-
end
|
147
|
-
|
148
|
-
old_stderr, $stderr = if client.stderr
|
149
|
-
[$stderr, client.stderr]
|
150
|
-
else
|
151
|
-
[$stderr, $stderr]
|
152
|
-
end
|
153
|
-
|
154
|
-
# Before Pry starts, save the pager config.
|
155
|
-
# We want to disable this because the pager won't do anything useful in
|
156
|
-
# this case (it will run on the server).
|
157
|
-
Pry.config.pager, old_pager = false, Pry.config.pager
|
158
|
-
|
159
|
-
# As above, but for system config
|
160
|
-
Pry.config.system, old_system = PryRemote::System, Pry.config.system
|
161
|
-
|
162
|
-
puts "[pry-remote] Client received, starting remote sesion"
|
163
|
-
Pry.start(self, :input => client.input_proxy, :output => client.output)
|
164
|
-
ensure
|
165
|
-
# Reset output streams
|
166
|
-
$stdout = old_stdout
|
167
|
-
$stderr = old_stderr
|
168
|
-
|
169
|
-
# Reset config
|
170
|
-
Pry.config.pager = old_pager
|
171
|
-
|
172
|
-
# Reset sysem
|
173
|
-
Pry.config.system = old_system
|
174
|
-
|
175
|
-
puts "[pry-remote] Remote sesion terminated"
|
176
|
-
client.kill
|
177
|
-
|
178
|
-
DRb.stop_service
|
179
|
-
end
|
207
|
+
def remote_pry(host = PryRemote::DefaultHost, port = PryRemote::DefaultPort)
|
208
|
+
PryRemote::Server.new(self, host, port).run
|
180
209
|
end
|
181
210
|
|
182
211
|
# a handy alias as many people may think the method is named after the gem
|
metadata
CHANGED
@@ -1,77 +1,71 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: pry-remote
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
4
5
|
prerelease:
|
5
|
-
version: 0.1.0
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Mon ouie
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-02-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: slop
|
17
|
-
|
18
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &6193840 !ruby/object:Gem::Requirement
|
19
17
|
none: false
|
20
|
-
requirements:
|
18
|
+
requirements:
|
21
19
|
- - ~>
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.1'
|
24
22
|
type: :runtime
|
25
|
-
version_requirements: *id001
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: pry
|
28
23
|
prerelease: false
|
29
|
-
|
24
|
+
version_requirements: *6193840
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: pry
|
27
|
+
requirement: &6192100 !ruby/object:Gem::Requirement
|
30
28
|
none: false
|
31
|
-
requirements:
|
29
|
+
requirements:
|
32
30
|
- - ~>
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: 0.9.
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.9.8
|
35
33
|
type: :runtime
|
36
|
-
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *6192100
|
37
36
|
description: Connect to Pry remotely using DRb
|
38
37
|
email: mon.ouie@gmail.com
|
39
|
-
executables:
|
38
|
+
executables:
|
40
39
|
- pry-remote
|
41
40
|
extensions: []
|
42
|
-
|
43
41
|
extra_rdoc_files: []
|
44
|
-
|
45
|
-
files:
|
42
|
+
files:
|
46
43
|
- lib/pry-remote.rb
|
47
44
|
- README.md
|
48
45
|
- bin/pry-remote
|
49
46
|
homepage: http://github.com/Mon-Ouie/pry-remote
|
50
47
|
licenses: []
|
51
|
-
|
52
48
|
post_install_message:
|
53
49
|
rdoc_options: []
|
54
|
-
|
55
|
-
require_paths:
|
50
|
+
require_paths:
|
56
51
|
- lib
|
57
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
53
|
none: false
|
59
|
-
requirements:
|
60
|
-
- -
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version:
|
63
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
59
|
none: false
|
65
|
-
requirements:
|
66
|
-
- -
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version:
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
69
64
|
requirements: []
|
70
|
-
|
71
65
|
rubyforge_project:
|
72
66
|
rubygems_version: 1.8.10
|
73
67
|
signing_key:
|
74
68
|
specification_version: 3
|
75
69
|
summary: Connect to Pry remotely
|
76
70
|
test_files: []
|
77
|
-
|
71
|
+
has_rdoc:
|