lib/alephant/broker/request/batch.rb in alephant-broker-3.10.2 vs lib/alephant/broker/request/batch.rb in alephant-broker-3.11.0

- old
+ new

@@ -8,26 +8,39 @@ include Logger attr_reader :batch_id, :components, :load_strategy def initialize(component_factory, env) - logger.info "Request::Batch#initialize: id: #{env.data['batch_id']}" if env.data + if env.data + @batch_id = env.data["batch_id"] + else + @batch_id = env.options.fetch("batch_id", nil) + end - @batch_id = env.data["batch_id"] if env.data + logger.info "Request::Batch#initialize: id: #{batch_id}" + @component_factory = component_factory - @components = components_for env + + @components = env.post? ? components_post(env) : components_get(env) end private - def components_for(env) + def components_post(env) ((env.data || {}).fetch("components", []) || []).map do |c| - @component_factory.create( - c["component"], - batch_id, - c["options"] - ) + 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