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.



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

def initialize
  @downcased = {}
end

Instance Method Details

#[](key) ⇒ Object



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

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

#assoc(obj) ⇒ Object



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

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

#delete(key, &proc) ⇒ Object



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

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

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



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

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



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

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

#merge!(other_hash) ⇒ Object



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

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

#raw_assocObject



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

alias_method :raw_assoc, :assoc

#raw_deleteObject



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

alias_method :raw_delete, :delete

#raw_fetchObject



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

alias_method :raw_fetch, :fetch

#raw_has_key?Object



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

alias_method :raw_has_key?, :has_key?

#raw_mergeObject



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

alias_method :raw_merge, :merge

#raw_merge!Object



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

alias_method :raw_merge!, :merge!

#raw_readerObject



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

alias_method :raw_reader, :[]

#raw_rehashObject



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

alias_method :raw_rehash, :rehash

#raw_values_atObject



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

alias_method :raw_values_at, :values_at

#raw_writerObject



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

alias_method :raw_writer, :[]=

#rehashObject



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

def rehash
  @downcased.rehash
  raw_rehash
end

#values_at(*keys) ⇒ Object



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

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