Sha256: cefaccb1ed0e3d8b4eb3b9568bcef03be4c120f6c8912de7a3dce5588a1a85c8
Contents?: true
Size: 1.51 KB
Versions: 1
Compression:
Stored size: 1.51 KB
Contents
require "crimp" require "alephant/storage" require "alephant/lookup" require "alephant/broker/errors/invalid_cache_key" require "alephant/sequencer" require "alephant/broker/cache" module Alephant module Broker class Component attr_reader :id, :batch_id, :options, :content, :opts_hash HEADER_PREFIX = "head_".freeze def initialize(meta, data) @id = meta.id @batch_id = meta.batch_id @options = symbolize(meta.options || {}) @content = data[:content].force_encoding "UTF-8" @opts_hash = meta.opts_hash @data = data @meta = meta end def content_type headers["Content-Type"] end def headers { "Content-Type" => data[:content_type].to_s } .merge(data[:headers] || {}) .merge(meta_data_headers) end def status data[:meta].key?("status") ? data[:meta]["status"] : 200 end private attr_reader :meta, :data def meta_data_headers @meta_data_headers ||= data[:meta].to_h.reduce({}) do |accum, (k, v)| accum.tap do |a| a[header_key(k.to_s)] = v.to_s if k.to_s.start_with?(HEADER_PREFIX) end end end def header_key(key) key = key.gsub(HEADER_PREFIX, "") return key if key == "ETag" key.split("-").map(&:capitalize).join("-") end def symbolize(hash) Hash[hash.map { |k, v| [k.to_sym, v] }] end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
alephant-broker-3.14.0 | lib/alephant/broker/component.rb |