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
# File 'lib/excon/headers.rb', line 24

def initialize
  @downcased = {}
end

Instance Method Details

#[](key) ⇒ Object


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

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

#assoc(obj) ⇒ Object


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

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

#delete(key, &proc) ⇒ Object


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

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

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


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

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

#merge(other_hash) ⇒ Object


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

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

#merge!(other_hash) ⇒ Object


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

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


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

def rehash
  @downcased.rehash
  raw_rehash
end

#values_at(*keys) ⇒ Object


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

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