Sha256: ef76eb118da9dc78cc8b3d1aeaad18bf2034a0d144804f8202c1024807360903

Contents?: true

Size: 965 Bytes

Versions: 2

Compression:

Stored size: 965 Bytes

Contents

require 'alephant/logger'
require 'alephant/broker/component'
require 'pmap'

module Alephant
  module Broker
    module Request
      class Batch
        include Logger

        attr_reader :batch_id, :components, :load_strategy

        def initialize(component_factory, env)
          logger.debug("Request::Batch#initialize(#{env.settings})")

          @component_factory = component_factory
          @batch_id   = env.data['batch_id']
          @components = components_for env

          logger.debug("Request::Batch#initialize: id: #{@batch_id}")
        end

        private

        def build_query(hash)
          hash.nil? ? '' : Rack::Utils.build_query(hash)
        end

        def components_for(env)
          env.data['components'].pmap do |c|
            @component_factory.create(
              c['component'],
              batch_id,
              build_query(c['options'])
            )
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
alephant-broker-2.1.0 lib/alephant/broker/request/batch.rb
alephant-broker-2.0.3 lib/alephant/broker/request/batch.rb