Class: Excon::Headers

Inherits:
Hash
  • Object
show all
Defined in:
lib/excon/headers.rb

Constant Summary collapse

SENTINEL =
{}

Instance Method Summary collapse

Constructor Details

#initializeHeaders

Returns a new instance of Headers.



24
25
26
27
# File 'lib/excon/headers.rb', line 24

def initialize
  super
  @downcased = {}
end

Instance Method Details

#[](key) ⇒ Object



29
30
31
# File 'lib/excon/headers.rb', line 29

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

#[]=(key, value) ⇒ Object Also known as: store



33
34
35
36
# File 'lib/excon/headers.rb', line 33

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

#assoc(obj) ⇒ Object



40
41
42
# File 'lib/excon/headers.rb', line 40

def assoc(obj)
  @downcased.assoc(obj.downcase)
end

#delete(key, &proc) ⇒ Object



45
46
47
48
# File 'lib/excon/headers.rb', line 45

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

#fetch(key, default = nil, &proc) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/excon/headers.rb', line 50

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

#has_key?(key) ⇒ Boolean Also known as: key?, member?

Returns:

  • (Boolean)


58
59
60
# File 'lib/excon/headers.rb', line 58

def has_key?(key)
  raw_key?(key) || @downcased.has_key?(key.to_s.downcase)
end

#merge(other_hash) ⇒ Object



64
65
66
# File 'lib/excon/headers.rb', line 64

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

#merge!(other_hash) ⇒ Object



68
69
70
71
72
73
# File 'lib/excon/headers.rb', line 68

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

#raw_assocObject



10
# File 'lib/excon/headers.rb', line 10

alias_method :raw_assoc, :assoc

#raw_deleteObject



12
# File 'lib/excon/headers.rb', line 12

alias_method :raw_delete, :delete

#raw_fetchObject



13
# File 'lib/excon/headers.rb', line 13

alias_method :raw_fetch, :fetch

#raw_has_key?Object



14
# File 'lib/excon/headers.rb', line 14

alias_method :raw_has_key?, :has_key?

#raw_mergeObject



18
# File 'lib/excon/headers.rb', line 18

alias_method :raw_merge, :merge

#raw_merge!Object



19
# File 'lib/excon/headers.rb', line 19

alias_method :raw_merge!, :merge!

#raw_readerObject



8
# File 'lib/excon/headers.rb', line 8

alias_method :raw_reader, :[]

#raw_rehashObject



20
# File 'lib/excon/headers.rb', line 20

alias_method :raw_rehash, :rehash

#raw_values_atObject



22
# File 'lib/excon/headers.rb', line 22

alias_method :raw_values_at, :values_at

#raw_writerObject



7
# File 'lib/excon/headers.rb', line 7

alias_method :raw_writer, :[]=

#rehashObject



75
76
77
78
# File 'lib/excon/headers.rb', line 75

def rehash
  @downcased.rehash
  raw_rehash
end

#values_at(*keys) ⇒ Object



80
81
82
# File 'lib/excon/headers.rb', line 80

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