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
23 24 25 26 |
# File 'lib/loco/ws_connection_manager.rb', line 23 def add(uuid) update uuid check_connections end |
#connected?(uuid) ⇒ Boolean
15 16 17 |
# File 'lib/loco/ws_connection_manager.rb', line 15 def connected?(uuid) connected_uuids.include? uuid end |
#connected_uuids ⇒ Object
19 20 21 |
# File 'lib/loco/ws_connection_manager.rb', line 19 def connected_uuids data.find_all { |_, v| v.is_a? String }.to_h.keys end |
#del(uuid) ⇒ Object
28 29 30 31 |
# File 'lib/loco/ws_connection_manager.rb', line 28 def del(uuid) save(data.tap { |h| h.delete uuid }) check_connections end |
#destroy ⇒ Object
37 38 39 |
# File 'lib/loco/ws_connection_manager.rb', line 37 def destroy WsConnectionStorage.current.del identifier end |
#identifier ⇒ Object
9 10 11 12 13 |
# 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
33 34 35 |
# File 'lib/loco/ws_connection_manager.rb', line 33 def update(uuid) save(data.tap { |h| h[uuid] = current_time }) end |