Class: Marvin::Distributed::Client::RemoteClientProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/marvin/distributed/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(conn, host_with_port, nickname) ⇒ RemoteClientProxy

Returns a new instance of RemoteClientProxy.



15
16
17
18
19
# File 'lib/marvin/distributed/client.rb', line 15

def initialize(conn, host_with_port, nickname)
  @connection     = conn
  @host_with_port = host_with_port
  @nickname       = nickname
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &blk) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/marvin/distributed/client.rb', line 29

def method_missing(name, *args, &blk)
  logger.debug "Proxying #{name}(#{args.inspect[1..-2]}) to #{@host_with_port}"
  cb = nil
  if blk.present?
    cb = proc do |_, options|
      if options.is_a?(Hash) 
        value = options.delete("return-value")
        blk.call(value)
      end
    end
  end
  @connection.send_message(:action, {
    "action"      => name.to_s,
    "arguments"   => args,
    "client-host" => @host_with_port
  }, &cb)
end

Instance Method Details

#host_with_portObject



25
26
27
# File 'lib/marvin/distributed/client.rb', line 25

def host_with_port
  @host_with_port
end

#nicknameObject



21
22
23
# File 'lib/marvin/distributed/client.rb', line 21

def nickname
  @nickname
end