Class: Coca::AuthCookie

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

Instance Method Summary collapse

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

Instance Method Details

#created_atObject

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

Returns:

  • (Boolean)


39
40
41
# File 'lib/coca/auth_cookie.rb', line 39

def present?
  @cookies[cookie_name].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[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)


44
45
46
# File 'lib/coca/auth_cookie.rb', line 44

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

#tokenObject



25
26
27
# File 'lib/coca/auth_cookie.rb', line 25

def token
  value[0]
end

#unsetObject

Unsets the cookie via the HTTP response.



21
22
23
# File 'lib/coca/auth_cookie.rb', line 21

def unset
  @cookies.delete cookie_name, cookie_options
end

#valid?Boolean

Whether the cookie appears valid.

Returns:

  • (Boolean)


35
36
37
# File 'lib/coca/auth_cookie.rb', line 35

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