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
- 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.
";,"
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
28 29 30 31 32 |
# File 'lib/hanami/action/cookie_jar.rb', line 28 def initialize(env, headers, ) @_headers = headers @cookies = Utils::Hash.deep_symbolize(extract(env)) @default_options = end |
Instance Method Details
#[](key) ⇒ Object?
Returns the object associated with the given key
60 61 62 |
# File 'lib/hanami/action/cookie_jar.rb', line 60 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
84 85 86 87 |
# File 'lib/hanami/action/cookie_jar.rb', line 84 def []=(key, value) changes << key @cookies[key] = value end |
#each(&blk) {|key, value| ... } ⇒ void
This method returns an undefined value.
Iterates cookies
110 111 112 |
# File 'lib/hanami/action/cookie_jar.rb', line 110 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.
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/hanami/action/cookie_jar.rb', line 42 def finish @cookies.delete(Action::RACK_SESSION) if changed? @cookies.each do |k, v| next unless changed?(k) v.nil? ? (k) : (k, _merge_default_values(v)) end end end |