Class: Droom::AuthCookie

Inherits:
Object
  • Object
show all
Defined in:
lib/droom/auth_cookie.rb

Instance Method Summary collapse

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

Instance Method Details

#created_atObject

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

Returns:

  • (Boolean)


36
37
38
# File 'lib/droom/auth_cookie.rb', line 36

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

#set_since?(time) ⇒ Boolean

Whether the cookie was set since the given Time

Returns:

  • (Boolean)


41
42
43
# File 'lib/droom/auth_cookie.rb', line 41

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

#store?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/droom/auth_cookie.rb', line 45

def store?
  false
end

#tokenObject



22
23
24
# File 'lib/droom/auth_cookie.rb', line 22

def token
  values[0]
end

#unsetObject

Unsets the cookie via the HTTP response.



18
19
20
# File 'lib/droom/auth_cookie.rb', line 18

def unset
  @cookies.delete cookie_name, cookie_options
end

#valid?Boolean

Whether the cookie appears valid.

Returns:

  • (Boolean)


32
33
34
# File 'lib/droom/auth_cookie.rb', line 32

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