Class: Loco::WsConnectionManager
- Inherits:
-
Object
- Object
- Loco::WsConnectionManager
- Defined in:
- lib/loco/ws_connection_manager.rb
Instance Method Summary collapse
- #add(uuid) ⇒ Object
- #connected?(uuid) ⇒ Boolean
- #connected_uuids ⇒ Object
- #del(uuid) ⇒ Object
- #destroy ⇒ Object
- #identifier ⇒ Object
-
#initialize(resource) ⇒ WsConnectionManager
constructor
A new instance of WsConnectionManager.
- #update(uuid) ⇒ Object
Constructor Details
#initialize(resource) ⇒ WsConnectionManager
Returns a new instance of WsConnectionManager.
5 6 7 |
# File 'lib/loco/ws_connection_manager.rb', line 5 def initialize resource @resource = resource end |
Instance Method Details
#add(uuid) ⇒ Object
22 23 24 25 |
# File 'lib/loco/ws_connection_manager.rb', line 22 def add uuid update uuid check_connections end |
#connected?(uuid) ⇒ Boolean
14 15 16 |
# File 'lib/loco/ws_connection_manager.rb', line 14 def connected? uuid connected_uuids.include? uuid end |
#connected_uuids ⇒ Object
18 19 20 |
# File 'lib/loco/ws_connection_manager.rb', line 18 def connected_uuids data.find_all { |_, v| v.is_a? String }.to_h.keys end |
#del(uuid) ⇒ Object
27 28 29 30 |
# File 'lib/loco/ws_connection_manager.rb', line 27 def del uuid save(data.tap { |h| h.delete uuid }) check_connections end |
#destroy ⇒ Object
36 37 38 |
# File 'lib/loco/ws_connection_manager.rb', line 36 def destroy WsConnectionStorage.current.del identifier end |
#identifier ⇒ Object
9 10 11 12 |
# File 'lib/loco/ws_connection_manager.rb', line 9 def identifier return @resource if @resource.is_a?(String) "#{@resource.class.name.downcase}:#{@resource.id}" end |
#update(uuid) ⇒ Object
32 33 34 |
# File 'lib/loco/ws_connection_manager.rb', line 32 def update uuid save(data.tap { |h| h[uuid] = current_time }) end |