Class: PryRemote::CLI
Overview
Parses arguments and allows to start the client.
Instance Attribute Summary collapse
-
#capture ⇒ Object
(also: #capture?)
readonly
Returns the value of attribute capture.
-
#host ⇒ String
readonly
Host of the server.
-
#port ⇒ Integer
readonly
Port of the server.
-
#wait ⇒ Object
(also: #wait?)
readonly
Returns the value of attribute wait.
Instance Method Summary collapse
-
#initialize(args = ARGV) ⇒ CLI
constructor
A new instance of CLI.
-
#run(input = Pry.config.input, output = Pry.config.output) ⇒ Object
Connects to the server.
-
#uri ⇒ String
URI for DRb.
Constructor Details
#initialize(args = ARGV) ⇒ CLI
Returns a new instance of CLI.
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/pry-remote.rb', line 234 def initialize(args = ARGV) params = Slop.parse args, :help => true do "#$PROGRAM_NAME [OPTIONS]" on :s, :server=, "Host of the server (#{DefaultHost})", :argument => :optional, :default => DefaultHost on :p, :port=, "Port of the server (#{DefaultPort})", :argument => :optional, :as => Integer, :default => DefaultPort on :w, :wait, "Wait for the pry server to come up", :default => false on :c, :capture, "Captures $stdout and $stderr from the server (true)", :default => true on :f, "Disables loading of .pryrc and its plugins, requires, and command history " end exit if params.help? @host = params[:server] @port = params[:port] @wait = params[:wait] @capture = params[:capture] Pry.initial_session_setup unless params[:f] end |
Instance Attribute Details
#capture ⇒ Object (readonly) Also known as: capture?
Returns the value of attribute capture.
272 273 274 |
# File 'lib/pry-remote.rb', line 272 def capture @capture end |
#host ⇒ String (readonly)
Returns Host of the server.
261 262 263 |
# File 'lib/pry-remote.rb', line 261 def host @host end |
#port ⇒ Integer (readonly)
Returns Port of the server.
264 265 266 |
# File 'lib/pry-remote.rb', line 264 def port @port end |
#wait ⇒ Object (readonly) Also known as: wait?
Returns the value of attribute wait.
271 272 273 |
# File 'lib/pry-remote.rb', line 271 def wait @wait end |
Instance Method Details
#run(input = Pry.config.input, output = Pry.config.output) ⇒ Object
Connects to the server
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/pry-remote.rb', line 280 def run(input = Pry.config.input, output = Pry.config.output) local_ip = UDPSocket.open {|s| s.connect(@host, 1); s.addr.last} DRb.start_service "druby://#{local_ip}:0" client = DRbObject.new(nil, uri) input = IOUndumpedProxy.new(input) output = IOUndumpedProxy.new(output) begin client.input = input client.output = output rescue DRb::DRbConnError => ex if wait? sleep 1 retry else raise ex end end if capture? client.stdout = $stdout client.stderr = $stderr end client.thread = Thread.current sleep DRb.stop_service end |
#uri ⇒ String
Returns URI for DRb.
267 268 269 |
# File 'lib/pry-remote.rb', line 267 def uri "druby://#{host}:#{port}" end |