Class: Rcom::Request
- Inherits:
-
Object
- Object
- Rcom::Request
- Defined in:
- lib/rcom/rpc.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Instance Method Summary collapse
-
#initialize(params) ⇒ Request
constructor
A new instance of Request.
- #method_missing(name, args) ⇒ Object
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
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
3 4 5 |
# File 'lib/rcom/rpc.rb', line 3 def channel @channel end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
3 4 5 |
# File 'lib/rcom/rpc.rb', line 3 def node @node end |