Class: Droom::AuthCookie
- Inherits:
-
Object
- Object
- Droom::AuthCookie
- Defined in:
- lib/droom/auth_cookie.rb
Instance Method Summary collapse
-
#created_at ⇒ Object
The Time at which the cookie was created.
-
#initialize(cookies) ⇒ AuthCookie
constructor
A new instance of AuthCookie.
- #present? ⇒ Boolean
-
#set(resource, opts = {}) ⇒ 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.
- #store? ⇒ Boolean
- #token ⇒ Object
-
#unset ⇒ Object
Unsets the cookie via the HTTP response.
-
#valid? ⇒ Boolean
Whether the cookie appears valid.
Constructor Details
#initialize(cookies) ⇒ AuthCookie
Returns a new instance of AuthCookie.
7 8 9 |
# File 'lib/droom/auth_cookie.rb', line 7 def initialize() @cookies = end |
Instance Method Details
#created_at ⇒ Object
The Time at which the cookie was created.
27 28 29 |
# File 'lib/droom/auth_cookie.rb', line 27 def created_at valid? ? DateTime.parse(values[1]) : nil end |
#present? ⇒ Boolean
36 37 38 |
# File 'lib/droom/auth_cookie.rb', line 36 def present? @cookies[].present? end |
#set(resource, opts = {}) ⇒ Object
Sets the cookie, referencing the given resource.id (e.g. User)
12 13 14 15 |
# File 'lib/droom/auth_cookie.rb', line 12 def set(resource, opts={}) = .merge(opts).merge(:value => set_auth_values(resource)) @cookies[] = end |
#set_since?(time) ⇒ Boolean
Whether the cookie was set since the given Time
41 42 43 |
# File 'lib/droom/auth_cookie.rb', line 41 def set_since?(time) created_at && created_at >= time end |
#store? ⇒ Boolean
45 46 47 |
# File 'lib/droom/auth_cookie.rb', line 45 def store? false end |
#token ⇒ Object
22 23 24 |
# File 'lib/droom/auth_cookie.rb', line 22 def token values[0] end |
#unset ⇒ Object
Unsets the cookie via the HTTP response.
18 19 20 |
# File 'lib/droom/auth_cookie.rb', line 18 def unset @cookies.delete , end |
#valid? ⇒ Boolean
Whether the cookie appears valid.
32 33 34 |
# File 'lib/droom/auth_cookie.rb', line 32 def valid? present? && values.all? end |