Sha256: 0389f9cafb9f6fd2ed2c0d3ff46b4a5b9870c4a33d32470438706d4f48b7bd37

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

require 'pry-remote'

module PryRemote
  class Server
    # Override the call to Pry.start to save off current Server, and not
    # teardown the server right after Pry.start finishes.
    def run
      if PryDebugger.current_remote_server
        raise 'Already running a pry-remote session!'
      else
        PryDebugger.current_remote_server = self
      end

      setup
      Pry.start @object, {
        :input  => client.input_proxy,
        :output => client.output
      }
    end

    # Override to reset our saved global current server session.
    alias_method :teardown_existing, :teardown
    def teardown
      return if @torn

      teardown_existing
      PryDebugger.current_remote_server = nil
      @torn = true
    end
  end
end

# Ensure cleanup when a program finishes without another break. For example,
# 'next' on the last line of a program won't hit PryDebugger::Processor#run,
# which normally handles cleanup.
at_exit do
  if PryDebugger.current_remote_server
    PryDebugger.current_remote_server.teardown
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pry-debugger-0.2.0 lib/pry-debugger/pry_remote_ext.rb