class Server

Attributes

client[R]

@return [PryServer::Client] Client connecting to the pry-remote server

host[R]

@return [String] Host of the server

object[R]

@return Object to enter into

port[R]

@return [Integer] Port of the server

unix[R]

@return [String] Unix domain socket path of the server

uri[R]

@return [String] URI for DRab

Public Class Methods

new(object, *args) click to toggle source
# File lib/pray-remote/pray-remote.rb, line 260
def initialize(object, *args)
  options = PrayRemote.kwargs(args)

  @host    = options[:host] || DefaultHost
  @port    = options[:port] || DefaultPort

  @unix = options[:unix] || false
  @secret = ""
  if options[:secret] != nil
    @secret = "?secret=" + options[:secret]
  end

  if @unix == false
    @uri = "druby://#{@host}:#{@port}#{@secret}"
    @unix = ""
  else
    @uri = "drabunix:#{@unix}"
  end

  @object  = object
  @options = options

  @client = PrayRemote::Client.new
  DRab.start_service @uri, @client
end
run(object, *args) click to toggle source
# File lib/pray-remote/pray-remote.rb, line 255
def self.run(object, *args)
  options = PrayRemote.kwargs(args)
  new(object, options).run
end

Public Instance Methods

capture_output() click to toggle source

Captures $stdout and $stderr if so requested by the client.

# File lib/pray-remote/pray-remote.rb, line 342
def capture_output
  $stdout = @client.stdout
  $stderr = @client.stderr
end
run() click to toggle source

Actually runs pry-remote

# File lib/pray-remote/pray-remote.rb, line 354
def run
  STDOUT.puts "[pry-remote] Waiting for client on #{uri}"
  @client.wait

  STDOUT.puts "[pry-remote] Client received, starting remote session"
  setup

  Pry.start(@object, @options.merge(:input => client.input_proxy,
                                    :output => client.output,
                                    :hooks => @hooks))
ensure
  teardown
end
setup() click to toggle source

Code that has to be called for Pry-remote to work properly

# File lib/pray-remote/pray-remote.rb, line 287
def setup
  if @client.stdout.nil?
    @client.stdout = $stdout
  end
  if @client.stderr.nil?
    @client.stderr = $stderr
  end
  @hooks = Pry::Hooks.new

  @hooks.add_hook :before_eval, :pry_remote_capture do
    capture_output
  end

  @hooks.add_hook :after_eval, :pry_remote_uncapture do
    uncapture_output
  end

  @hooks.add_hook :before_session, :pry_instance_get do |output, bind, mypry|
    #puts mypry.class
    #puts mypry.methods
    @client.mypry = mypry
  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 = PrayRemote::System, Pry.config.system

  Pry.config.editor, @old_editor = nil, Pry.config.editor
  #binding.pry # for testing attacks on clients
end
teardown() click to toggle source

Code that has to be called after setup to return to the initial state

# File lib/pray-remote/pray-remote.rb, line 323
def teardown
  # Reset config
  Pry.config.editor = @old_editor
  Pry.config.pager  = @old_pager
  Pry.config.system = @old_system

  STDOUT.puts "[pry-remote] Remote session terminated"

  begin
    @client.kill
  rescue DRab::DRabConnError
    STDOUT.puts "[pry-remote] Continuing to stop service"
  ensure
    STDOUT.puts "[pry-remote] Ensure stop service"
    DRab.stop_service
  end
end
uncapture_output() click to toggle source

Resets $stdout and $stderr to their previous values.

# File lib/pray-remote/pray-remote.rb, line 348
def uncapture_output
  $stdout = STDOUT
  $stderr = STDOUT
end