Method: Meshchat::Network::Message::Factory#create

Defined in:
lib/meshchat/network/message/factory.rb

#create(type = '', data: {}) ⇒ Object

If data contains the payload key, we are receiving the message. If data does not caine the payload key, we are buliding the message to send



40
41
42
43
44
45
46
47
48
# File 'lib/meshchat/network/message/factory.rb', line 40

def create(type = '', data: {})
  return Debug.message_type_not_found(type + 'not found') if type.blank?
  data = data.deep_symbolize_keys

  parameters = parameters_for(data)
  klass = TYPES[type]
  raise Errors::MessageTypeNotRecognized, type + ' not found' unless klass
  klass.new(parameters)
end