Module: Wamp::MessageHandler::ClassMethods

Included in:
Wamp::MessageHandler
Defined in:
lib/wamp/message_handler.rb

Overview

instantiate correct handler

Instance Method Summary collapse

Instance Method Details

#constantize(camel_cased_word) ⇒ Object



69
70
71
# File 'lib/wamp/message_handler.rb', line 69

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

#demodulize(path) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/wamp/message_handler.rb', line 60

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

#from(message, connection) ⇒ Object



54
55
56
57
58
# File 'lib/wamp/message_handler.rb', line 54

def from(message, connection)
  klass_name = demodulize(message.class.name)
  klass = constantize("Wamp::MessageHandler::#{klass_name}")
  klass.new(message, connection)
end

#handle_when_not_joined(data, connection) ⇒ Object



47
48
49
50
51
52
# File 'lib/wamp/message_handler.rb', line 47

def handle_when_not_joined(data, connection)
  authenticate = connection.joiner.receive(data) # maybe welcome message then state should be joined
  connection.transmit authenticate unless connection.joiner.joined?
  connection.executor.call(connection.api) if connection.joiner.joined?
  Struct.new(:handle).new
end

#resolve(data, connection) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/wamp/message_handler.rb', line 38

def resolve(data, connection)
  # return handle_when_not_joined(data, connection) unless connection.joiner.joined?

  message = connection.joiner.serializer.deserialize(data)
  klass_name = demodulize(message.class.name)
  klass = constantize("Wamp::MessageHandler::#{klass_name}")
  klass.new(message, connection)
end