Sha256: a7f91e8d70ebd45dbd1307fdf46dde4d35520268cb5a9540b72d4ae3e62ea2a3

Contents?: true

Size: 948 Bytes

Versions: 5

Compression:

Stored size: 948 Bytes

Contents

# frozen_string_literal: true

module Loco
  class WsConnectionManager
    EXPIRATION = 60 * 3

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

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

    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

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

    private

    def identifier
      @identifier ||= WsConnectionIdentifier.(@resource)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
loco-rails-7.0.0.pre lib/loco/ws_connection_manager.rb
loco-rails-6.2.0 lib/loco/ws_connection_manager.rb
loco-rails-6.1.0 lib/loco/ws_connection_manager.rb
loco-rails-6.0.0 lib/loco/ws_connection_manager.rb
loco-rails-5.0.0 lib/loco/ws_connection_manager.rb