Class: DeviseLoginCookie::Cookie

Inherits:
Object
  • Object
show all
Defined in:
lib/devise_login_cookie/cookie.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(cookies, scope)
  @cookies = cookies
  @scope = scope
end

Instance Attribute Details

#secret_tokenObject

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 session_options=(value)
  @session_options = value
end

Instance Method Details

#created_atObject

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

#idObject

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

Returns:

  • (Boolean)


41
42
43
# File 'lib/devise_login_cookie/cookie.rb', line 41

def present?
  @cookies[cookie_name].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[cookie_name] = cookie_options.merge(:value => encoded_value(resource))
end

#set_since?(time) ⇒ Boolean

Whether the cookie was set since the given Time

Returns:

  • (Boolean)


46
47
48
# File 'lib/devise_login_cookie/cookie.rb', line 46

def set_since?(time)
  created_at && created_at >= time
end

#unsetObject

Unsets the cookie via the HTTP response.



22
23
24
# File 'lib/devise_login_cookie/cookie.rb', line 22

def unset
  @cookies.delete cookie_name, cookie_options
end

#valid?Boolean

Whether the cookie appears valid.

Returns:

  • (Boolean)


37
38
39
# File 'lib/devise_login_cookie/cookie.rb', line 37

def valid?
  present? && value.all?
end