Class: DDP::Server::RethinkDB::WebSocket
- Inherits:
-
WebSocket
- Object
- WebSocket
- DDP::Server::RethinkDB::WebSocket
- Defined in:
- lib/ddp/server/rethinkdb/websocket.rb
Overview
Implementation of the WebSocket DDP::Server
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
Returns the value of attribute api.
Class Method Summary collapse
Instance Method Summary collapse
- #handle_method(id, method, params) ⇒ Object
- #handle_sub(id, name, params) ⇒ Object
- #handle_unsub(id) ⇒ Object
-
#initialize(api_class, config) ⇒ WebSocket
constructor
A new instance of WebSocket.
- #subscription_update(id, change) ⇒ Object
Constructor Details
#initialize(api_class, config) ⇒ WebSocket
12 13 14 15 |
# File 'lib/ddp/server/rethinkdb/websocket.rb', line 12 def initialize(api_class, config) @api = api_class.new(config) @subscriptions = {} end |
Instance Attribute Details
#api ⇒ Object (readonly)
Returns the value of attribute api.
6 7 8 |
# File 'lib/ddp/server/rethinkdb/websocket.rb', line 6 def api @api end |
Class Method Details
.rack(api, config, pool_config = {}) ⇒ Object
8 9 10 |
# File 'lib/ddp/server/rethinkdb/websocket.rb', line 8 def self.rack(api, config, pool_config = {}) super(pool_config.merge(args: [api, config])) end |
Instance Method Details
#handle_method(id, method, params) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/ddp/server/rethinkdb/websocket.rb', line 43 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_sub(id, name, params) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/ddp/server/rethinkdb/websocket.rb', line 17 def handle_sub(id, name, params) params ||= [] query = @api.collection_query(name, *params) @subscriptions[id] = Subscription.new(self, id, name, query) rescue => e send_error_result(id, e) end |
#handle_unsub(id) ⇒ Object
37 38 39 40 41 |
# File 'lib/ddp/server/rethinkdb/websocket.rb', line 37 def handle_unsub(id) subscription = @subscriptions.delete(id) subscription.stop unless subscription.nil? send_nosub(id) end |
#subscription_update(id, change) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ddp/server/rethinkdb/websocket.rb', line 25 def subscription_update(id, change) subscription_name = @subscriptions[id].name old_value = change['old_val'] new_value = change['new_val'] return send_added(subscription_name, new_value['id'], new_value) if old_value.nil? return send_removed(subscription_name, old_value['id']) if new_value.nil? cleared = old_value.keys.reject { |key| new_value.include? key } send_changed(subscription.name, old_value['id'], new_value, cleared) end |