Class: RabbitRPC::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/rabbit_rpc/config.rb

Constant Summary collapse

@@service_address =
{}

Class Method Summary collapse

Class Method Details

.client_rpc_pathObject



12
13
14
# File 'lib/rabbit_rpc/config.rb', line 12

def client_rpc_path
  @@rpc_path ||= File.join 'config', 'rabbit_rpc.yml'
end

.client_rpc_path=(path) ⇒ Object



16
17
18
# File 'lib/rabbit_rpc/config.rb', line 16

def client_rpc_path=(path)
  @@rpc_path = path
end

.initialize!Object

Traverses through the RPC YAML file and creates RPC invocations under the RabbitRPC::Client namespace.

UserService:

Authorization: auth
Friend: list, delete

RabbitRPC::Client::UserService::Friends.list TODO: Abstract this logic into a seperate class



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rabbit_rpc/config.rb', line 29

def initialize!
  YAML.load_file(client_rpc_path).each do |service_name, class_definitions|
    unless class_definitions.is_a?(Hash) && class_definitions.keys.sort == %w[address methods]
      raise InvalidFormatError, "Error parsing the structure of the RPC YAML"
    end

    mdule        = Module.new
    service_name = "#{service_name}".classify

    ::RabbitRPC::Client.const_set service_name, mdule
    class_definitions.each do |param, value|
      if is_address?(param)
        @@service_address ||= {}
        @@service_address[service_name] = value
      elsif is_method_declaration?(param)
        populate_rpc(service_name, value)
      end
    end
  end
end