Sha256: 949ddb478285ace299be299679251f259c3fb5c58473ec44e3b9c3aecf34bf09

Contents?: true

Size: 1.84 KB

Versions: 52

Compression:

Stored size: 1.84 KB

Contents

# frozen_string_literal: true
module Excon
  class Headers < Hash

    SENTINEL = {}

    alias_method :raw_writer, :[]=
    alias_method :raw_reader, :[]
    if SENTINEL.respond_to?(:assoc)
      alias_method :raw_assoc, :assoc
    end
    alias_method :raw_delete, :delete
    alias_method :raw_fetch, :fetch
    alias_method :raw_has_key?, :has_key?
    alias_method :raw_include?, :include?
    alias_method :raw_key?, :key?
    alias_method :raw_member?, :member?
    alias_method :raw_merge, :merge
    alias_method :raw_merge!, :merge!
    alias_method :raw_rehash, :rehash
    alias_method :raw_store, :store
    alias_method :raw_values_at, :values_at

    def initialize
      super
      @downcased = {}
    end

    def [](key)
      @downcased[key.to_s.downcase]
    end

    def []=(key, value)
      raw_writer(key, value)
      @downcased[key.to_s.downcase] = value
    end
    alias_method :store, :[]=

    if SENTINEL.respond_to? :assoc
      def assoc(obj)
        @downcased.assoc(obj.downcase)
      end
    end

    def delete(key, &proc)
      raw_delete(key, &proc)
      @downcased.delete(key.to_s.downcase, &proc)
    end

    def fetch(key, default = nil, &proc)
      if proc
        @downcased.fetch(key.to_s.downcase, &proc)
      else
        @downcased.fetch(key.to_s.downcase, default)
      end
    end

    def has_key?(key)
      raw_key?(key) || @downcased.has_key?(key.to_s.downcase)
    end
    alias_method :key?, :has_key?
    alias_method :member?, :has_key?

    def merge(other_hash)
      self.dup.merge!(other_hash)
    end

    def merge!(other_hash)
      other_hash.each do |key, value|
        self[key] = value
      end
      raw_merge!(other_hash)
    end

    def rehash
      @downcased.rehash
      raw_rehash
    end

    def values_at(*keys)
      @downcased.values_at(*keys.map {|key| key.to_s.downcase})
    end

  end
end

Version data entries

52 entries across 51 versions & 2 rubygems

Version Path
excon-0.97.2 lib/excon/headers.rb
excon-0.97.1 lib/excon/headers.rb
excon-0.97.0 lib/excon/headers.rb
excon-0.96.0 lib/excon/headers.rb
excon-0.95.0 lib/excon/headers.rb
excon-0.94.0 lib/excon/headers.rb
excon-0.93.1 lib/excon/headers.rb
excon-0.93.0 lib/excon/headers.rb
excon-0.92.5 lib/excon/headers.rb
excon-0.92.4 lib/excon/headers.rb
excon-0.92.3 lib/excon/headers.rb
excon-0.92.2 lib/excon/headers.rb
excon-0.92.1 lib/excon/headers.rb
excon-0.92.0 lib/excon/headers.rb
excon-0.91.0 lib/excon/headers.rb
excon-0.90.0 lib/excon/headers.rb
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/excon-0.88.0/lib/excon/headers.rb
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/excon-0.89.0/lib/excon/headers.rb
excon-0.89.0 lib/excon/headers.rb
vagrant-unbundled-2.2.18.0 vendor/bundle/ruby/3.0.0/gems/excon-0.88.0/lib/excon/headers.rb