Class: Loco::WsConnectionManager

Inherits:
Object
  • Object
show all
Defined in:
lib/loco/ws_connection_manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ WsConnectionManager

Returns a new instance of WsConnectionManager.



3
4
5
# File 'lib/loco/ws_connection_manager.rb', line 3

def initialize resource
  @resource = resource
end

Instance Method Details

#add(uuid) ⇒ Object



20
21
22
23
# File 'lib/loco/ws_connection_manager.rb', line 20

def add uuid
  update uuid
  check_connections
end

#connected?(uuid) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/loco/ws_connection_manager.rb', line 12

def connected? uuid
  connected_uuids.include? uuid
end

#connected_uuidsObject



16
17
18
# File 'lib/loco/ws_connection_manager.rb', line 16

def connected_uuids
  data.find_all{ |k,v| v.is_a? String }.to_h.keys
end

#del(uuid) ⇒ Object



25
26
27
28
# File 'lib/loco/ws_connection_manager.rb', line 25

def del uuid
  save data.tap{ |h| h.delete uuid }
  check_connections
end

#destroyObject



34
35
36
# File 'lib/loco/ws_connection_manager.rb', line 34

def destroy
  WsConnectionStorage.current.del identifier
end

#identifierObject



7
8
9
10
# File 'lib/loco/ws_connection_manager.rb', line 7

def identifier
  return @resource if @resource.is_a?(String)
  "#{@resource.class.name.downcase}:#{@resource.id}"
end

#update(uuid) ⇒ Object



30
31
32
# File 'lib/loco/ws_connection_manager.rb', line 30

def update uuid
  save data.tap{ |h| h[uuid] = current_time }
end