class DontStallMyProcess::Remote::RemoteProxy

RemoteProxy is an decorator class for any of the ‘real’ classes to be served via DRb. It delegates method calls to the encapsulated instance of the ‘real’ class. Furthermore, it takes care of creating nested DRb services as requested in the option hash.

Attributes

uri[R]

Public Class Methods

new(opts, instance, parent = nil) click to toggle source
# File lib/dont-stall-my-process/remote/remote_proxy.rb, line 19
def initialize(opts, instance, parent = nil)
  @opts     = opts
  @object   = instance

  @uri      = "drbunix:///tmp/dsmp-#{Process.ppid}-#{SecureRandom.hex(8)}"
  @server   = DRb.start_service(@uri, self)

  RemoteProxy.register(Process.pid, @uri, self)
end

Public Instance Methods

__local_proxy_destroyed() click to toggle source
# File lib/dont-stall-my-process/remote/remote_proxy.rb, line 29
def __local_proxy_destroyed
  __destroy
end
method_missing(meth, *args, &block) click to toggle source
Calls superclass method
# File lib/dont-stall-my-process/remote/remote_proxy.rb, line 37
def method_missing(meth, *args, &block)
  case
  when (mopts = @opts[:methods][meth])
    __create_nested_proxy(meth, *args, &block)
  when @object.respond_to?(meth)
    # Delegate the method call to the real object.
    @object.public_send(meth, *args, &block)
  else
    super
  end
end
respond_to?(m, ia = false) click to toggle source
Calls superclass method
# File lib/dont-stall-my-process/remote/remote_proxy.rb, line 33
def respond_to?(m, ia = false)
  @opts[:methods].keys.include?(m) || @object.respond_to?(m, ia) || super(m, ia)
end

Private Instance Methods

__create_nested_proxy(meth, *args, &block) click to toggle source
# File lib/dont-stall-my-process/remote/remote_proxy.rb, line 51
def __create_nested_proxy(meth, *args, &block)
  instance = @object.public_send(meth, *args, &block)

  # Start the proxy, convert the object into a DRb service.
  RemoteProxy.new(@opts[:methods][meth], instance, self).uri
end
__destroy() click to toggle source
# File lib/dont-stall-my-process/remote/remote_proxy.rb, line 58
def __destroy
  @server.stop_service
  FileUtils.rm_f(@uri)

  RemoteProxy.unregister(Process.pid, @uri)
end