Module: CitrusRpc::RpcServer::Dispatcher

Included in:
Gateway
Defined in:
lib/citrus-rpc/rpc-server/dispatcher.rb

Overview

Dispatcher

Instance Method Summary collapse

Instance Method Details

#dispatch(msg, services, &block) ⇒ Object

Dispatch message to appropriate service object

Parameters:

  • msg (Hash)
  • services (Hash)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/citrus-rpc/rpc-server/dispatcher.rb', line 18

def dispatch msg, services, &block
  unless namespace = services[msg['namespace']]
    block.call Exception.new 'no such namespace: ' + msg['namespace']
    return
  end
  unless service = namespace[msg['service']]
    block.call Exception.new 'no such service: ' + msg['service']
    return
  end
  unless service.respond_to? msg['method']
    block.call Exception.new 'no such method: ' + msg['method']
    return
  end

  service.send msg['method'], *msg['args'], &block
end