Sha256: 1a8b910b8208057bb37c31dc9707abe202b49639d29636ff43e3d41e5cec2bd7

Contents?: true

Size: 898 Bytes

Versions: 5

Compression:

Stored size: 898 Bytes

Contents

# frozen_string_literal: true

require "wsdirector/protocols/base"
require "wsdirector/protocols/action_cable"
require "wsdirector/protocols/phoenix"

module WSDirector
  ID2CLASS = {
    "base" => "Base",
    "action_cable" => "ActionCable",
    "phoenix" => "Phoenix"
  }.freeze

  module Protocols # :nodoc:
    # Raised when received not expected message
    class UnmatchedExpectationError < WSDirector::Error; end

    # Raised when received message is unexpected
    class UnexpectedMessageError < WSDirector::Error; end

    # Raised when nothing has been received
    class NoMessageError < WSDirector::Error; end

    class << self
      def get(id)
        class_name = if ID2CLASS.key?(id)
          ID2CLASS.fetch(id)
        else
          id
        end

        const_get(class_name)
      rescue NameError
        raise Error, "Unknown protocol: #{id}"
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
wsdirector-core-1.1.0 lib/wsdirector/protocols.rb
wsdirector-core-1.0.3 lib/wsdirector/protocols.rb
wsdirector-core-1.0.2 lib/wsdirector/protocols.rb
wsdirector-core-1.0.1 lib/wsdirector/protocols.rb
wsdirector-core-1.0.0 lib/wsdirector/protocols.rb