Sha256: 45d44c0cbaf1cf6c92c98d102172889d7a4d6bc6d6bb08220aefc33c1ac94030

Contents?: true

Size: 1.02 KB

Versions: 5

Compression:

Stored size: 1.02 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'
          :components_batch
        when 'component'
          :component
        when 'status'
          :status
        else
          :notfound
        end
      end

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
alephant-broker-0.1.6 lib/alephant/broker/models/request_handler.rb
alephant-broker-0.1.5 lib/alephant/broker/models/request_handler.rb
alephant-broker-0.1.4 lib/alephant/broker/models/request_handler.rb
alephant-broker-0.1.3 lib/alephant/broker/models/request_handler.rb
alephant-broker-0.1.2 lib/alephant/broker/models/request_handler.rb