Class: Hanami::Action::CookieJar
- Inherits:
-
Object
- Object
- Hanami::Action::CookieJar
- Defined in:
- lib/hanami/action/cookie_jar.rb
Overview
A set of HTTP Cookies
It acts as an Hash
Constant Summary collapse
- HTTP_HEADER =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The key that returns raw cookies from the Rack env
'HTTP_COOKIE'.freeze
- RACK_SESSION_KEY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The key used by Rack to set the session cookie
We let CookieJar to NOT take care of this cookie, but it leaves the responsibility to the Rack middleware that handle sessions.
This prevents
Set-Cookie
to be sent twice. :'rack.session'
- COOKIE_HASH_KEY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The key used by Rack to set the cookies as an Hash in the env
'rack.request.cookie_hash'.freeze
- COOKIE_STRING_KEY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The key used by Rack to set the cookies as a String in the env
'rack.request.cookie_string'.freeze
- COOKIE_SEPARATOR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
';,'.freeze
Instance Method Summary collapse
-
#[](key) ⇒ Object?
Returns the object associated with the given key.
-
#[]=(key, value) ⇒ void
Associate the given value with the given key and store them.
-
#each(&blk) {|key, value| ... } ⇒ void
Iterates cookies.
-
#finish ⇒ void
Finalize itself, by setting the proper headers to add and remove cookies, before the response is returned to the webserver.
-
#initialize(env, headers, default_options) ⇒ CookieJar
constructor
Initialize the CookieJar.
Constructor Details
#initialize(env, headers, default_options) ⇒ CookieJar
Initialize the CookieJar
56 57 58 59 60 |
# File 'lib/hanami/action/cookie_jar.rb', line 56 def initialize(env, headers, ) @_headers = headers @cookies = Utils::Hash.new(extract(env)).deep_symbolize! @default_options = end |
Instance Method Details
#[](key) ⇒ Object?
Returns the object associated with the given key
85 86 87 |
# File 'lib/hanami/action/cookie_jar.rb', line 85 def [](key) @cookies[key] end |
#[]=(key, value) ⇒ void
This method returns an undefined value.
Associate the given value with the given key and store them
109 110 111 112 |
# File 'lib/hanami/action/cookie_jar.rb', line 109 def []=(key, value) changes << key @cookies[key] = value end |
#each(&blk) {|key, value| ... } ⇒ void
This method returns an undefined value.
Iterates cookies
135 136 137 |
# File 'lib/hanami/action/cookie_jar.rb', line 135 def each(&blk) @cookies.each(&blk) end |
#finish ⇒ void
This method returns an undefined value.
Finalize itself, by setting the proper headers to add and remove cookies, before the response is returned to the webserver.
70 71 72 73 74 75 76 |
# File 'lib/hanami/action/cookie_jar.rb', line 70 def finish @cookies.delete(RACK_SESSION_KEY) @cookies.each do |k,v| next unless changed?(k) v.nil? ? (k) : (k, _merge_default_values(v)) end if changed? end |