Sha256: 53dce9f4fea339ce07ba914ebd87fbea7f11ced2b7890b638272686630175a48

Contents?: true

Size: 529 Bytes

Versions: 8

Compression:

Stored size: 529 Bytes

Contents

# frozen_string_literal: true

module Kiev
  module Kafka
    class MessageContext
      # @param [Kafka::FetchedMessage] message
      def initialize(message)
        @headers = message.headers
      end

      def value(field)
        headers[header_key(field)] || headers[field.to_s]
      end

      alias_method :[], :value

      private

      attr_reader :headers

      # @param [String] field
      def header_key(field)
        "x_#{field}".gsub("_", " ").split.map(&:capitalize).join("-")
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
kiev-4.9.0 lib/kiev/kafka/message_context.rb
kiev-4.8.3 lib/kiev/kafka/message_context.rb
kiev-4.8.2 lib/kiev/kafka/message_context.rb
kiev-4.8.1 lib/kiev/kafka/message_context.rb
kiev-4.8.0 lib/kiev/kafka/message_context.rb
kiev-4.7.0 lib/kiev/kafka/message_context.rb
kiev-4.6.0 lib/kiev/kafka/message_context.rb
kiev-4.5.0 lib/kiev/kafka/message_context.rb