Sha256: c001c68dc7d119e2f3d5a1a2b1f3daf4757b716e81a613d78f1a7a9aa263d9ee

Contents?: true

Size: 1.53 KB

Versions: 3

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

require_relative "event/hello"
require_relative "event/welcome"
require_relative "event/abort"
require_relative "event/challenge"
require_relative "event/authenticate"
require_relative "event/goodbye"

require_relative "event/error"

require_relative "event/subscribe"
require_relative "event/subscribed"
require_relative "event/unsubscribe"
require_relative "event/unsubscribed"
require_relative "event/publish"
require_relative "event/published"
require_relative "event/event"

require_relative "event/call"
require_relative "event/result"

require_relative "event/register"
require_relative "event/registered"

require_relative "event/unregister"
require_relative "event/unregistered"

require_relative "event/invocation"
require_relative "event/yield"

module Wamp
  module Manager
    # handles creating correct event managers
    module Event
      # methods responsbile for instantiating correct event
      module ClassMethods
        def resolve(message, session)
          klass_name = demodulize(message.class.name)
          klass = constantize("Wamp::Manager::Event::#{klass_name}")
          klass.new(message, session)
        end

        def demodulize(path)
          path = path.to_s
          if i = path.rindex("::") # rubocop:disable Lint/AssignmentInCondition
            path[(i + 2), path.length]
          else
            path
          end
        end

        def constantize(camel_cased_word)
          Object.const_get(camel_cased_word)
        end
      end
      extend ClassMethods
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
xconn-0.1.2 lib/wamp/manager/event.rb
xconn-0.1.1 lib/wamp/manager/event.rb
xconn-0.1.0 lib/wamp/manager/event.rb