Class: Rack::Request::Headers
- Inherits:
-
Object
- Object
- Rack::Request::Headers
- Defined in:
- lib/inferno/ext/rack.rb
Instance Method Summary collapse
-
#[](k) ⇒ Object
-
#[]=(k, v) ⇒ Object
-
#add(k, v) ⇒ Object
-
#delete(k) ⇒ Object
-
#each ⇒ Object
-
#fetch(k, &block) ⇒ Object
-
#has_key?(k) ⇒ Boolean
-
#initialize(env) ⇒ Headers
constructor
A new instance of Headers.
-
#to_h ⇒ Object
Constructor Details
#initialize(env) ⇒ Headers
Returns a new instance of Headers.
11 12 13 |
# File 'lib/inferno/ext/rack.rb', line 11 def initialize(env) @env = env end |
Instance Method Details
#[](k) ⇒ Object
15 16 17 |
# File 'lib/inferno/ext/rack.rb', line 15 def [](k) @env[header_to_env_key(k)] end |
#[]=(k, v) ⇒ Object
19 20 21 |
# File 'lib/inferno/ext/rack.rb', line 19 def []=(k, v) @env[header_to_env_key(k)] = v end |
#add(k, v) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/inferno/ext/rack.rb', line 23 def add(k, v) k = header_to_env_key(k) case existing = @env[k] when nil @env[k] = v when String @env[k] = [existing, v] when Array existing << v end end |
#delete(k) ⇒ Object
35 36 37 |
# File 'lib/inferno/ext/rack.rb', line 35 def delete(k) @env.delete(header_to_env_key(k)) end |
#each ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/inferno/ext/rack.rb', line 39 def each return to_enum(:each) unless block_given? @env.each do |k, v| next unless k = env_to_header_key(k) yield k, v end end |
#fetch(k, &block) ⇒ Object
48 49 50 |
# File 'lib/inferno/ext/rack.rb', line 48 def fetch(k, &block) @env.fetch(header_to_env_key(k), &block) end |
#has_key?(k) ⇒ Boolean
52 53 54 |
# File 'lib/inferno/ext/rack.rb', line 52 def has_key?(k) @env.has_key?(header_to_env_key(k)) end |
#to_h ⇒ Object
56 57 58 59 60 |
# File 'lib/inferno/ext/rack.rb', line 56 def to_h h = {} each{|k, v| h[k] = v} h end |