Module: PryRemote::Server
Overview
Extraction of Object#remote_pry from github.com/Mon-Ouie/pry-remote/blob/master/lib/pry-remote.rb into separate ‘start` and `stop` methods so that a DRb session can last over multiple Pry.start calls.
Instance Method Summary collapse
Instance Method Details
#start(host, port) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/pry-nav/pry_remote_ext.rb', line 13 def start(host, port) uri = "druby://#{host}:#{port}" @client = PryRemote::Client.new @started = true DRb.start_service uri, @client puts "[pry-remote] Waiting for client on #{uri}" @client.wait # If client passed stdout and stderr, redirect actual messages there. @old_stdout, $stdout = if @client.stdout [$stdout, @client.stdout] else [$stdout, $stdout] end @old_stderr, $stderr = if @client.stderr [$stderr, @client.stderr] else [$stderr, $stderr] end # Before Pry starts, save the pager config. # We want to disable this because the pager won't do anything useful in # this case (it will run on the server). Pry.config.pager, @old_pager = false, Pry.config.pager # As above, but for system config Pry.config.system, @old_system = PryRemote::System, Pry.config.system @client end |
#stop ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/pry-nav/pry_remote_ext.rb', line 49 def stop return unless @started # Reset output streams $stdout = @old_stdout $stderr = @old_stderr # Reset config Pry.config.pager = @old_pager # Reset system Pry.config.system = @old_system begin @client.kill rescue DRb::DRbConnError # Ignore connection errors. The CLI client may have killed itself. ensure DRb.stop_service end @started = false puts "[pry-remote] Remote sesion terminated" end |