class RfLogger::RequestHeaders

Attributes

api_token[R]
content_type[R]
other[R]
request_id[R]
type[R]

Public Class Methods

new(type: "application/json", api_token: nil, request_id: self.class.request_id, other: {}, **other_key_headers) click to toggle source
# File lib/rf_logger/request/request_headers.rb, line 5
def initialize(type: "application/json",
               api_token: nil,
               request_id: self.class.request_id,
               other: {},
               **other_key_headers)
  @type              = type
  @api_token         = api_token
  @request_id        = request_id
  @content_type      = type
  @other             = other
  @other_key_headers = other_key_headers
end
request_id() click to toggle source
# File lib/rf_logger/request/request_headers.rb, line 18
def self.request_id
  (Thread.current.get_inheritable_attribute(:rf_logger_request_tags)||{})[:request_id]
end

Public Instance Methods

other_key_headers() click to toggle source
# File lib/rf_logger/request/request_headers.rb, line 30
def other_key_headers
  @other_key_headers.each_with_object({}) { |(k, v), h| h[k.to_s.split("_").map(&:capitalize).join("-")] = v }
end
to_hash() click to toggle source
# File lib/rf_logger/request/request_headers.rb, line 22
def to_hash
  {
    "Content-Type" => content_type,
    "Api-Token"    => api_token,
    "X-Request-Id" => request_id
  }.merge(other_key_headers).merge(other).reject { |_, v| v.nil? }
end