Module: Alondra::CommandDispatcher

Extended by:
CommandDispatcher
Included in:
CommandDispatcher
Defined in:
lib/alondra/command_dispatcher.rb

Instance Method Summary collapse

Instance Method Details

#dispatch(input, connection) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/alondra/command_dispatcher.rb', line 8

def dispatch(input, connection)
  msg = parse(input)

  unless msg.kind_of?(Hash) && msg[:command].present?
    raise NotRecognizedCommand.new("Unrecognized command: #{input}")
  end

  Command.new(connection, msg).execute!
end

#parse(string) ⇒ Object



18
19
20
# File 'lib/alondra/command_dispatcher.rb', line 18

def parse(string)
  msg = ActiveSupport::JSON.decode(string).symbolize_keys
end