Module: DDP::Server::Protocol::RPC
- Included in:
- DDP::Server::Protocol
- Defined in:
- lib/ddp/server/protocol/rpc.rb
Overview
Protocol regarding remote procedure calls
Constant Summary collapse
- NO_RESULT =
Object.new
Instance Method Summary collapse
- #handle_method(id, method, params) ⇒ Object
- #handle_rpc ⇒ Object
- #send_error_result(id, error) ⇒ Object
- #send_result(id, result = NO_RESULT) ⇒ Object
- #send_updated(methods) ⇒ Object
Instance Method Details
#handle_method(id, method, params) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/ddp/server/protocol/rpc.rb', line 18 def handle_method(id, method, params) params ||= [] result = api.invoke_rpc(method, *params) send_result(id, result) rescue => e send_error_result(id, e) end |
#handle_rpc ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/ddp/server/protocol/rpc.rb', line 8 def handle_rpc case @message['msg'] when 'method' handle_method(@message['id'], @message['method'], @message['params']) true else false end end |
#send_error_result(id, error) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/ddp/server/protocol/rpc.rb', line 32 def send_error_result(id, error) = { msg: 'result', id: id } ['error'] = { error: error.class.name, reason: error., details: "Backtrace: \n#{error.backtrace.join("\n")}" } () end |
#send_result(id, result = NO_RESULT) ⇒ Object
26 27 28 29 30 |
# File 'lib/ddp/server/protocol/rpc.rb', line 26 def send_result(id, result = NO_RESULT) = { msg: 'result', id: id } ['result'] = result unless result == NO_RESULT () end |
#send_updated(methods) ⇒ Object
42 43 44 |
# File 'lib/ddp/server/protocol/rpc.rb', line 42 def send_updated(methods) msg: 'updated', methods: methods end |