Class: Rcom::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/rcom/rpc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Request

Returns a new instance of Request.



5
6
7
8
# File 'lib/rcom/rpc.rb', line 5

def initialize(params)
  @node = params[:node]
  @channel = params[:channel]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rcom/rpc.rb', line 10

def method_missing(name, args)
  begin
    request = {
      id: SecureRandom.hex,
      method: name,
      args: args || ''
    }

    node.rpush(channel, request.to_msgpack)
    ch, response = node.brpop(request[:id], timeout=10)

    MessagePack.unpack(response, symbolize_keys: true)
  rescue
    return nil
  end
end

Instance Attribute Details

#channelObject (readonly)

Returns the value of attribute channel.



3
4
5
# File 'lib/rcom/rpc.rb', line 3

def channel
  @channel
end

#nodeObject (readonly)

Returns the value of attribute node.



3
4
5
# File 'lib/rcom/rpc.rb', line 3

def node
  @node
end