Sha256: 8539cbb44cdb736b4d44898924d03dafd4b7606e44970db328b147d1fa03a812

Contents?: true

Size: 1.27 KB

Versions: 9

Compression:

Stored size: 1.27 KB

Contents

require "alephant/logger"
require "alephant/broker/component"

module Alephant
  module Broker
    module Request
      class Batch
        include Logger

        attr_reader :batch_id, :components, :load_strategy

        def initialize(component_factory, env)
          @batch_id = if env.data
                        env.data["batch_id"]
                      else
                        env.options.fetch("batch_id", nil)
                      end

          logger.info "Request::Batch#initialize: id: #{batch_id}"

          @component_factory = component_factory

          @components        = env.post? ? components_post(env) : components_get(env)
        end

        private

        def components_post(env)
          ((env.data || {}).fetch("components", []) || []).map do |c|
            create_component(c["component"], batch_id, c["options"])
          end
        end

        def components_get(env)
          (env.options.fetch("components", []) || []).map do |c|
            options = c[1].fetch("options", {}) || {}
            create_component(c[1]["component"], batch_id, options)
          end
        end

        def create_component(component, batch_id, options)
          @component_factory.create(component, batch_id, options)
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
alephant-broker-3.18.0 lib/alephant/broker/request/batch.rb
alephant-broker-3.17.0 lib/alephant/broker/request/batch.rb
alephant-broker-3.16.2 lib/alephant/broker/request/batch.rb
alephant-broker-3.16.1 lib/alephant/broker/request/batch.rb
alephant-broker-3.16.0 lib/alephant/broker/request/batch.rb
alephant-broker-3.15.2 lib/alephant/broker/request/batch.rb
alephant-broker-3.15.1 lib/alephant/broker/request/batch.rb
alephant-broker-3.15.0 lib/alephant/broker/request/batch.rb
alephant-broker-3.14.0 lib/alephant/broker/request/batch.rb