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.
-
#persist ⇒ Object
(also: #persist?)
readonly
Returns the value of attribute persist.
-
#port ⇒ Integer
readonly
Port of the server.
-
#wait ⇒ Object
(also: #wait?)
readonly
Returns the value of attribute wait.
Instance Method Summary collapse
-
#cleanup(client) ⇒ Object
Clean up the client.
-
#connect(input = Pry.config.input, output = Pry.config.output) ⇒ Object
Connects to the server.
-
#initialize(args = ARGV) ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
-
#uri ⇒ String
URI for DRb.
Constructor Details
#initialize(args = ARGV) ⇒ CLI
Returns a new instance of CLI.
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/pry-remote.rb', line 262 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 :r, :persist, "Persist the client to wait for the pry server to come up each time", :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] @persist = params[:persist] @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.
304 305 306 |
# File 'lib/pry-remote.rb', line 304 def capture @capture end |
#host ⇒ String (readonly)
Returns Host of the server.
292 293 294 |
# File 'lib/pry-remote.rb', line 292 def host @host end |
#persist ⇒ Object (readonly) Also known as: persist?
Returns the value of attribute persist.
303 304 305 |
# File 'lib/pry-remote.rb', line 303 def persist @persist end |
#port ⇒ Integer (readonly)
Returns Port of the server.
295 296 297 |
# File 'lib/pry-remote.rb', line 295 def port @port end |
#wait ⇒ Object (readonly) Also known as: wait?
Returns the value of attribute wait.
302 303 304 |
# File 'lib/pry-remote.rb', line 302 def wait @wait end |
Instance Method Details
#cleanup(client) ⇒ Object
Clean up the client
356 357 358 359 360 361 362 363 |
# File 'lib/pry-remote.rb', line 356 def cleanup(client) begin # The method we are calling here doesn't matter. # This is a hack to close the connection of DRb. client.cleanup rescue DRb::DRbConnError, NoMethodError end end |
#connect(input = Pry.config.input, output = Pry.config.output) ⇒ Object
Connects to the server
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
# File 'lib/pry-remote.rb', line 320 def connect(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) cleanup(client) input = IOUndumpedProxy.new(input) output = IOUndumpedProxy.new(output) begin client.input = input client.output = output rescue DRb::DRbConnError => ex if wait? || persist? sleep 1 retry else raise ex end end if capture? client.stdout = $stdout client.stderr = $stderr end client.editor = ClientEditor client.thread = Thread.current sleep DRb.stop_service end |
#run ⇒ Object
309 310 311 312 313 314 |
# File 'lib/pry-remote.rb', line 309 def run while true connect break unless persist? end end |
#uri ⇒ String
Returns URI for DRb.
298 299 300 |
# File 'lib/pry-remote.rb', line 298 def uri "druby://#{host}:#{port}" end |