Class: Flexirest::HeadersList
- Inherits:
-
Object
- Object
- Flexirest::HeadersList
- Defined in:
- lib/flexirest/headers_list.rb
Constant Summary collapse
- STORE_MULTIPLE_VALUES =
["set-cookie"]
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #delete(key) ⇒ Object
- #each(split_multiple_headers = false) ⇒ Object
-
#initialize ⇒ HeadersList
constructor
A new instance of HeadersList.
- #keys ⇒ Object
Constructor Details
#initialize ⇒ HeadersList
Returns a new instance of HeadersList.
5 6 7 |
# File 'lib/flexirest/headers_list.rb', line 5 def initialize @store = {} end |
Instance Method Details
#[](key) ⇒ Object
19 20 21 22 |
# File 'lib/flexirest/headers_list.rb', line 19 def [](key) key = find_existing(key) @store[key] end |
#[]=(key, value) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/flexirest/headers_list.rb', line 9 def []=(key,value) key = find_existing(key) if STORE_MULTIPLE_VALUES.include?(key.downcase) @store[key] ||= [] @store[key] << value else @store[key] = value end end |
#delete(key) ⇒ Object
37 38 39 40 |
# File 'lib/flexirest/headers_list.rb', line 37 def delete(key) key = find_existing(key) @store.delete(key) end |
#each(split_multiple_headers = false) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/flexirest/headers_list.rb', line 24 def each(split_multiple_headers = false) @store.keys.each do |key| value = @store[key] if value.is_a?(Array) && split_multiple_headers value.each do |inner_value| yield(key, inner_value) end else yield(key, value) end end end |
#keys ⇒ Object
42 43 44 |
# File 'lib/flexirest/headers_list.rb', line 42 def keys @store.keys end |