Sha256: 522666ee67a7533c32c7679f9e24e83e353580cefd86604a61b50b9a31777a88

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

require 'alephant/broker/models/request_factory'
require 'alephant/broker/models/response_factory'

module Alephant
  module Broker
    class RequestHandler
      include Logger

      def initialize(config)
        @config = config
      end

      def process
        begin
          response_factory.response_from(request)
        rescue Exception => e
          logger.info("Broker.requestHandler.process: Exception raised (#{e.message})")
          response_factory.response(500)
        end
      end

      private

      def request
        @request ||= RequestFactory.process(request_type)
      end

      def response_factory
        @response_factory ||= ResponseFactory.new(@config)
      end

      def request_type
        case env.request_type
        when 'components'
          component_type
        when 'status'
          :status
        else
          :notfound
        end
      end

      def component_type
        case env.method
        when 'POST'
          :component_batch
        when 'GET'
          :component
        end
      end

      def env
        @env ||= RequestStore.store[:env]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
alephant-broker-0.1.1 lib/alephant/broker/models/request_handler.rb