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.



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

Returns:

  • (Boolean)


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

def connected?(uuid)
  connected_uuids.include? uuid
end

#connected_uuidsObject



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

#destroyObject



37
38
39
# File 'lib/loco/ws_connection_manager.rb', line 37

def destroy
  WsConnectionStorage.current.del identifier
end

#identifierObject



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