Class: Cybertrain::CookieJar
- Inherits:
-
Object
- Object
- Cybertrain::CookieJar
- Defined in:
- cybertrain/cookie_jar.rb
Overview
The request’s cookies, from Cybertrain::Controller#cookies. Names are Strings or
Symbols; values are Strings. A write takes a String, or a Hash with
value: and any of expires: (a Time), max_age: (seconds),
path: ("/"), httponly: (true), secure: (Config#session_secure)
and same_site: ("Lax").
Instance Method Summary collapse
-
#[](name) ⇒ String?
The cookie’s value as the request sent it (or as this request wrote it), nil when there is none.
-
#[]=(name, value) ⇒ String
Writes the cookie (see the class comment for the Hash form).
-
#delete(name, path: "/") ⇒ String?
Deletes the cookie: a Set-Cookie with an empty value and
Max-Age=0atpath. -
#encrypted ⇒ EncryptedCookieJar
The jar of encrypted cookies.
-
#permanent ⇒ PermanentCookieJar
The jar whose writes last 20 years (
Max-Age=631139040) unless they giveexpires:ormax_age:. -
#signed ⇒ SignedCookieJar
The jar of signed cookies.
Instance Method Details
#[](name) ⇒ String?
The cookie’s value as the request sent it (or as this request wrote it), nil when there is none.
100 101 102 |
# File 'cybertrain/cookie_jar.rb', line 100 def [](name) @cookies[name.to_s] end |
#[]=(name, value) ⇒ String
Writes the cookie (see the class comment for the Hash form).
109 110 111 |
# File 'cybertrain/cookie_jar.rb', line 109 def []=(name, value) (name.to_s, value, PLAIN, false) end |
#delete(name, path: "/") ⇒ String?
Deletes the cookie: a Set-Cookie with an empty value and Max-Age=0
at path. Returns the value it had.
119 120 121 122 123 124 |
# File 'cybertrain/cookie_jar.rb', line 119 def delete(name, path: "/") key = name.to_s = Cookies.serialize(key, "", path: path, max_age: 0, secure: @secure) @response.(key, ) @cookies.delete(key) end |
#encrypted ⇒ EncryptedCookieJar
The jar of encrypted cookies.
147 148 149 150 |
# File 'cybertrain/cookie_jar.rb', line 147 def encrypted EncryptedCookieJar.new(self, false) end |
#permanent ⇒ PermanentCookieJar
The jar whose writes last 20 years (Max-Age=631139040) unless they
give expires: or max_age:.
130 131 132 |
# File 'cybertrain/cookie_jar.rb', line 130 def permanent PermanentCookieJar.new(self) end |
#signed ⇒ SignedCookieJar
The jar of signed cookies.
138 139 140 141 |
# File 'cybertrain/cookie_jar.rb', line 138 def signed SignedCookieJar.new(self, false) end |