Class: Userbin::CookieStore::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/userbin/support/cookie_store.rb

Instance Method Summary collapse

Constructor Details

#initialize(request, response) ⇒ Base

Returns a new instance of Base.



4
5
6
7
# File 'lib/userbin/support/cookie_store.rb', line 4

def initialize(request, response)
  @request = request
  @response = response
end

Instance Method Details

#[](key) ⇒ Object



9
10
11
# File 'lib/userbin/support/cookie_store.rb', line 9

def [](key)
  @request.cookies[key]
end

#[]=(key, value) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/userbin/support/cookie_store.rb', line 13

def []=(key, value)
  @request.cookies[key] = value
  if value
    @response.set_cookie(key, value: value,
                              expires: Time.now + (20 * 365 * 24 * 60 * 60),
                              path: '/')
  else
    @response.delete_cookie(key)
  end
end