Sha256: 0f04e724b53a0a8ad91b745f988421e08b87442098243ca4ee747177b6a20e7e

Contents?: true

Size: 750 Bytes

Versions: 1

Compression:

Stored size: 750 Bytes

Contents

# frozen_string_literal: true

module LiteCable
  module Channel
    # Stores channels identifiers and corresponding classes.
    module Registry
      class Error < StandardError; end
      class AlreadyRegisteredError < Error; end
      class UnknownChannelError < Error; end

      class << self
        def add(id, channel_class)
          raise AlreadyRegisteredError if find(id)
          channels[id] = channel_class
        end

        def find(id)
          channels[id]
        end

        def find!(id)
          channel_class = find(id)
          raise UnknownChannelError unless channel_class
          channel_class
        end

        private

        def channels
          @channels ||= {}
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
litecable-0.5.0 lib/lite_cable/channel/registry.rb