Class: DeviseLoginCookie::Cookie
- Inherits:
-
Object
- Object
- DeviseLoginCookie::Cookie
- Defined in:
- lib/devise_login_cookie/cookie.rb
Instance Attribute Summary collapse
-
#secret_token ⇒ Object
Returns the value of attribute secret_token.
-
#session_options ⇒ Object
writeonly
for non-Rails test environment.
Instance Method Summary collapse
-
#created_at ⇒ Object
The Time at which the cookie was created.
-
#id ⇒ Object
The id of the resource (e.g. User) referenced in the cookie.
-
#initialize(cookies, scope) ⇒ Cookie
constructor
A new instance of Cookie.
- #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.
-
#unset ⇒ Object
Unsets the cookie via the HTTP response.
-
#valid? ⇒ Boolean
Whether the cookie appears valid.
Constructor Details
#initialize(cookies, scope) ⇒ Cookie
Returns a new instance of Cookie.
11 12 13 14 |
# File 'lib/devise_login_cookie/cookie.rb', line 11 def initialize(, scope) @cookies = @scope = scope end |
Instance Attribute Details
#secret_token ⇒ Object
Returns the value of attribute secret_token.
9 10 11 |
# File 'lib/devise_login_cookie/cookie.rb', line 9 def secret_token @secret_token end |
#session_options=(value) ⇒ Object (writeonly)
for non-Rails test environment.
8 9 10 |
# File 'lib/devise_login_cookie/cookie.rb', line 8 def (value) @session_options = value end |
Instance Method Details
#created_at ⇒ Object
The Time at which the cookie was created.
32 33 34 |
# File 'lib/devise_login_cookie/cookie.rb', line 32 def created_at valid? ? Time.at(value[1]) : nil end |
#id ⇒ Object
The id of the resource (e.g. User) referenced in the cookie.
27 28 29 |
# File 'lib/devise_login_cookie/cookie.rb', line 27 def id value[0] end |
#present? ⇒ Boolean
41 42 43 |
# File 'lib/devise_login_cookie/cookie.rb', line 41 def present? @cookies[].present? end |
#set(resource) ⇒ Object
Sets the cookie, referencing the given resource.id (e.g. User)
17 18 19 |
# File 'lib/devise_login_cookie/cookie.rb', line 17 def set(resource) @cookies[] = .merge(:value => encoded_value(resource)) end |
#set_since?(time) ⇒ Boolean
Whether the cookie was set since the given Time
46 47 48 |
# File 'lib/devise_login_cookie/cookie.rb', line 46 def set_since?(time) created_at && created_at >= time end |
#unset ⇒ Object
Unsets the cookie via the HTTP response.
22 23 24 |
# File 'lib/devise_login_cookie/cookie.rb', line 22 def unset @cookies.delete , end |
#valid? ⇒ Boolean
Whether the cookie appears valid.
37 38 39 |
# File 'lib/devise_login_cookie/cookie.rb', line 37 def valid? present? && value.all? end |