Sha256: 546b8179df3059aa7c0d828399a85bc03e43c1b28a6964a73129974abdf51e77

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 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})"
          result = components.map do |component|
            {
              'component'    => component.id,
              'options'      => component.options,
              'status'       => component.status,
              'content_type' => component.content_type,
              'body'         => component.content
            }
          end
          logger.info "Broker: Batch load done (#{batch_id})"

          result
        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/response/batch.rb
alephant-broker-2.0.3 lib/alephant/broker/response/batch.rb