Sha256: 040929a98537599b369a042b1a605bb6893a3649b051fc77b4f738d21bdaee99

Contents?: true

Size: 889 Bytes

Versions: 5

Compression:

Stored size: 889 Bytes

Contents

# frozen_string_literal: true

module Loco
  class WsConnectionFinder
    class << self
      def call(resources, &block)
        storage = WsConnectionStorage.current
        resources = [resources] unless resources.is_a?(Array)
        resources.each do |resource|
          case resource
          when :all then storage.scan(all: true, &block)
          when Hub then search_the_hub(resource, &block)
          when Class
            storage.scan(match: "#{WsConnectionIdentifier.(resource)}:*", &block)
          else
            storage.members(WsConnectionIdentifier.(resource)).each(&block)
          end
        end
      end

      private

      def search_the_hub(resource, &block)
        WsConnectionStorage.current.members(resource.full_name).map do |serialized|
          WsConnectionStorage.current.members(serialized).each(&block)
        end
      end
    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_finder.rb
loco-rails-6.2.0 lib/loco/ws_connection_finder.rb
loco-rails-6.1.0 lib/loco/ws_connection_finder.rb
loco-rails-6.0.0 lib/loco/ws_connection_finder.rb
loco-rails-5.0.0 lib/loco/ws_connection_finder.rb