Class: Loco::WsConnectionManager

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

Constant Summary collapse

EXPIRATION =
60 * 3

Instance Method Summary collapse

Constructor Details

#initialize(resource, opts = {}) ⇒ WsConnectionManager

Returns a new instance of WsConnectionManager.



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

def initialize(resource, opts = {})
  if opts[:identifier]
    @identifier = resource
  else
    @resource = resource
  end
end

Instance Method Details

#add(uuid) ⇒ Object



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

def add(uuid)
  WsConnectionStorage.current.add(identifier, uuid)
  WsConnectionStorage.current.add("uuid:#{uuid}", identifier)
  update(uuid)
  WsConnectionChecker.(identifier, skip: uuid)
end

#del(uuid, skip_checker: false) ⇒ Object



22
23
24
25
26
27
# File 'lib/loco/ws_connection_manager.rb', line 22

def del(uuid, skip_checker: false)
  WsConnectionStorage.current.rem(identifier, uuid)
  WsConnectionStorage.current.rem("uuid:#{uuid}", identifier)
  WsConnectionStorage.current.del(uuid)
  WsConnectionChecker.(identifier) unless skip_checker
end

#update(uuid) ⇒ Object



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

def update(uuid)
  WsConnectionStorage.current.set(uuid, 'ok', ex: EXPIRATION)
end