Sha256: 6103c4c127cd2b7172cf36ecbba3610b07fb0a49268ffa04c0ee3d84bc5c9ae3

Contents?: true

Size: 1.11 KB

Versions: 7

Compression:

Stored size: 1.11 KB

Contents

module Alephant
  module Broker
    class ComponentMeta
      attr_reader :id, :options, :batch_id
      attr_accessor :cached

      def initialize(id, batch_id, options)
        @id          = id
        @batch_id    = batch_id
        @options     = convert_keys(options || {})
        @cached      = true
      end

      def cache_key
        "#{id}/#{opts_hash}/#{version}"
      end

      def version
        Broker.config.fetch(
          'elasticache_cache_version', 'not available'
        ).to_s
      end

      def key
        batch_id.nil? ? component_key : renderer_key
      end

      def opts_hash
        Crimp.signature options
      end

      private

      def convert_keys(hash)
        Hash[ hash.map { |k, v| [k.to_sym, v] } ]
      end

      def component_key
        "#{id}/#{opts_hash}"
      end

      def renderer_key
        "#{batch_id}/#{opts_hash}"
      end

      def headers(data)
        {
          'Content-Type' => data[:content_type].to_s,
          'X-Version'    => version.to_s,
          'X-Cached'     => cached.to_s
        }.merge(data[:headers] || {})
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
alephant-broker-3.2.0 lib/alephant/broker/component_meta.rb
alephant-broker-3.1.1 lib/alephant/broker/component_meta.rb
alephant-broker-3.1.0 lib/alephant/broker/component_meta.rb
alephant-broker-3.0.1 lib/alephant/broker/component_meta.rb
alephant-broker-3.0.0 lib/alephant/broker/component_meta.rb
alephant-broker-2.1.3 lib/alephant/broker/component_meta.rb
alephant-broker-2.1.2 lib/alephant/broker/component_meta.rb