Sha256: 55a2d2e62836dd71286f14519513f30dc6da758ae3007cf6f25162bc902ea070

Contents?: true

Size: 469 Bytes

Versions: 4

Compression:

Stored size: 469 Bytes

Contents

module Alondra

  class NotRecognizedCommand < StandardError; end

  module CommandDispatcher
    extend self

    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

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
alondra-0.1.1 lib/alondra/command_dispatcher.rb
alondra-0.1.0 lib/alondra/command_dispatcher.rb
alondra-0.0.4 lib/alondra/command_dispatcher.rb
alondra-0.0.3 lib/alondra/command_dispatcher.rb