Class: Coca::AuthCookie
- Inherits:
-
Object
- Object
- Coca::AuthCookie
- Defined in:
- lib/coca/auth_cookie.rb
Instance Method Summary collapse
-
#created_at ⇒ Object
The Time at which the cookie was created.
-
#initialize(cookies, scope) ⇒ AuthCookie
constructor
A new instance of AuthCookie.
- #present? ⇒ Boolean
-
#set(resource) ⇒ Object
Sets the cookie, referencing the given resource.id (e.g. User).
-
#set_since?(time) ⇒ Boolean
Whether the cookie was set since the given Time.
- #token ⇒ Object
-
#unset ⇒ Object
Unsets the cookie via the HTTP response.
-
#valid? ⇒ Boolean
Whether the cookie appears valid.
Constructor Details
#initialize(cookies, scope) ⇒ AuthCookie
Returns a new instance of AuthCookie.
10 11 12 13 |
# File 'lib/coca/auth_cookie.rb', line 10 def initialize(, scope) @cookies = @scope = scope end |
Instance Method Details
#created_at ⇒ Object
The Time at which the cookie was created.
30 31 32 |
# File 'lib/coca/auth_cookie.rb', line 30 def created_at valid? ? Time.at(value[1]) : nil end |
#present? ⇒ Boolean
39 40 41 |
# File 'lib/coca/auth_cookie.rb', line 39 def present? @cookies[].present? end |
#set(resource) ⇒ Object
Sets the cookie, referencing the given resource.id (e.g. User)
16 17 18 |
# File 'lib/coca/auth_cookie.rb', line 16 def set(resource) @cookies[] = .merge(:value => encoded_value(resource)) end |
#set_since?(time) ⇒ Boolean
Whether the cookie was set since the given Time
44 45 46 |
# File 'lib/coca/auth_cookie.rb', line 44 def set_since?(time) created_at && created_at >= time end |
#token ⇒ Object
25 26 27 |
# File 'lib/coca/auth_cookie.rb', line 25 def token value[0] end |
#unset ⇒ Object
Unsets the cookie via the HTTP response.
21 22 23 |
# File 'lib/coca/auth_cookie.rb', line 21 def unset @cookies.delete , end |
#valid? ⇒ Boolean
Whether the cookie appears valid.
35 36 37 |
# File 'lib/coca/auth_cookie.rb', line 35 def valid? present? && value.all? end |