Sha256: 72af3ab6c4eea2179dacb5fbb3a5875b46a1c896aa3e31432d5eb7eeee1b6940

Contents?: true

Size: 1 KB

Versions: 3

Compression:

Stored size: 1 KB

Contents

require 'alephant/logger'

module Alephant
  module Broker
    module Response
      class Batch < Base
        include Logger

        attr_reader :components, :batch_id

        def initialize(components, batch_id)
          @components = components
          @batch_id   = batch_id

          super(200, 'application/json')
        end

        def setup
          @content = ::JSON.generate({
            'batch_id' => batch_id,
            'components' => json
          })
        end

        private

        def json
          logger.info "Broker: Batch load started (#{batch_id})"
          components.map do |component|
            {
              'component'    => component.id,
              'options'      => component.options,
              'status'       => component.status,
              'content_type' => component.content_type,
              'body'         => component.content
            }
          end.tap { logger.info "Broker: Batch load done (#{batch_id})" }
        end

      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
alephant-broker-3.6.1 lib/alephant/broker/response/batch.rb
alephant-broker-3.6.0 lib/alephant/broker/response/batch.rb
alephant-broker-3.5.5 lib/alephant/broker/response/batch.rb