pry-remote 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/pry-remote.rb +94 -18
  2. metadata +2 -2
@@ -5,7 +5,7 @@ require 'readline'
5
5
  require 'open3'
6
6
 
7
7
  module PryRemote
8
- DefaultHost = "localhost"
8
+ DefaultHost = "127.0.0.1"
9
9
  DefaultPort = 9876
10
10
 
11
11
  # A class to represent an input object created from DRb. This is used because
@@ -15,7 +15,74 @@ module PryRemote
15
15
  InputProxy = Struct.new :input do
16
16
  # Reads a line from the input
17
17
  def readline(prompt)
18
- input.readline(prompt)
18
+ case readline_arity
19
+ when 1 then input.readline(prompt)
20
+ else input.readline
21
+ end
22
+ end
23
+
24
+ def completion_proc=(val)
25
+ input.completion_proc = val
26
+ end
27
+
28
+ def readline_arity
29
+ input.method_missing(:method, :readline).arity
30
+ rescue NameError
31
+ 0
32
+ end
33
+ end
34
+
35
+ # Class used to wrap inputs so that they can be sent through DRb.
36
+ #
37
+ # This is to ensure the input is used locally and not reconstructed on the
38
+ # server by DRb.
39
+ class IOUndumpedProxy
40
+ include DRb::DRbUndumped
41
+
42
+ def initialize(obj)
43
+ @obj = obj
44
+ end
45
+
46
+ def completion_proc=(val)
47
+ if @obj.respond_to? :completion_proc=
48
+ @obj.completion_proc = val
49
+ end
50
+ end
51
+
52
+ def completion_proc
53
+ @obj.completion_proc if @obj.respond_to? :completion_proc
54
+ end
55
+
56
+ def readline(prompt)
57
+ if @obj.method(:readline).arity == 1
58
+ @obj.readline(prompt)
59
+ else
60
+ $stdout.print prompt
61
+ @obj.readline
62
+ end
63
+ end
64
+
65
+ def puts(*lines)
66
+ @obj.puts(*lines)
67
+ end
68
+
69
+ def print(*objs)
70
+ @obj.print(*objs)
71
+ end
72
+
73
+ def write(data)
74
+ @obj.write data
75
+ end
76
+
77
+ def <<(data)
78
+ @obj << data
79
+ self
80
+ end
81
+
82
+ # Some versions of Pry expect $stdout or its output objects to respond to
83
+ # this message.
84
+ def tty?
85
+ false
19
86
  end
20
87
  end
21
88
 
@@ -65,7 +132,7 @@ module PryRemote
65
132
  new(object, host, port).run
66
133
  end
67
134
 
68
- def initialize(object, host = "loclahost", port = DefaultPort)
135
+ def initialize(object, host = DefaultHost, port = DefaultPort)
69
136
  @uri = "druby://#{host}:#{port}"
70
137
  @object = object
71
138
 
@@ -115,9 +182,15 @@ module PryRemote
115
182
  Pry.config.system = @old_system
116
183
 
117
184
  puts "[pry-remote] Remote session terminated"
118
- @client.kill
119
185
 
120
- DRb.stop_service
186
+ begin
187
+ @client.kill
188
+ rescue DRb::DRbConnError
189
+ puts "[pry-remote] Continuing to stop service"
190
+ ensure
191
+ puts "[pry-remote] Ensure stop service"
192
+ DRb.stop_service
193
+ end
121
194
  end
122
195
 
123
196
  # Actually runs pry-remote
@@ -141,18 +214,23 @@ module PryRemote
141
214
  params = Slop.parse args, :help => true do
142
215
  banner "#$PROGRAM_NAME [OPTIONS]"
143
216
 
144
- on :h, :host, "Host of the server (#{DefaultHost})", true,
217
+ on :s, :server=, "Host of the server (#{DefaultHost})", :argument => :optional,
145
218
  :default => DefaultHost
146
- on :p, :port, "Port of the server (#{DefaultPort})", true,
219
+ on :p, :port=, "Port of the server (#{DefaultPort})", :argument => :optional,
147
220
  :as => Integer, :default => DefaultPort
148
221
  on :c, :capture, "Captures $stdout and $stderr from the server (true)",
149
222
  :default => true
223
+ on :f, "Disables loading of .pryrc and its plugins, requires, and command history "
150
224
  end
151
225
 
152
- @host = params[:host]
226
+ exit if params.help?
227
+
228
+ @host = params[:server]
153
229
  @port = params[:port]
154
230
 
155
231
  @capture = params[:capture]
232
+
233
+ Pry.initial_session_setup unless params[:f]
156
234
  end
157
235
 
158
236
  # @return [String] Host of the server
@@ -170,21 +248,19 @@ module PryRemote
170
248
  alias capture? capture
171
249
 
172
250
  # Connects to the server
173
- def run
251
+ #
252
+ # @param [IO] input Object holding input for pry-remote
253
+ # @param [IO] output Object pry-debug will send its output to
254
+ def run(input = Pry.config.input, output = Pry.config.output)
174
255
  DRb.start_service
175
256
  client = DRbObject.new(nil, uri)
176
257
 
177
- # Passing Readline to DRb won't actually make it use our readline
178
- # object. Instead, it will use the server-side readilne. Therefore, we
179
- # create a simple proxy here.
180
-
181
- input = Object.new
182
- def input.readline(prompt)
183
- Readline.readline(prompt, true)
184
- end
258
+ input = IOUndumpedProxy.new(input)
259
+ output = IOUndumpedProxy.new(output)
185
260
 
186
261
  client.input = input
187
- client.output = $stdout
262
+
263
+ client.output = output
188
264
 
189
265
  if capture?
190
266
  client.stdout = $stdout
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-remote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-15 00:00:00.000000000 Z
12
+ date: 2013-03-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: slop