Class: Juno::Adapters::Cookie

Inherits:
Memory show all
Defined in:
lib/juno/adapters/cookie.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Memory

#key?, #load

Methods inherited from Base

#[], #[]=, #close, #fetch

Constructor Details

#initialize(options = {}) ⇒ Cookie

Returns a new instance of Cookie.



6
7
8
9
# File 'lib/juno/adapters/cookie.rb', line 6

def initialize(options = {})
  super
  @options, @cookies = options, {}
end

Instance Attribute Details

#cookiesObject (readonly)

Returns the value of attribute cookies.



4
5
6
# File 'lib/juno/adapters/cookie.rb', line 4

def cookies
  @cookies
end

Instance Method Details

#clear(options = {}) ⇒ Object



24
25
26
27
28
# File 'lib/juno/adapters/cookie.rb', line 24

def clear(options = {})
  @memory.each_key { |key| @cookies[key] = nil }
  super
  self
end

#delete(key, options = {}) ⇒ Object



19
20
21
22
# File 'lib/juno/adapters/cookie.rb', line 19

def delete(key, options = {})
  @cookies[key] = nil
  super
end

#reset(cookies) ⇒ Object



30
31
32
# File 'lib/juno/adapters/cookie.rb', line 30

def reset(cookies)
  @cookies, @memory = {}, cookies
end

#store(key, value, options = {}) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/juno/adapters/cookie.rb', line 11

def store(key, value, options = {})
  cookie = @options.merge(options)
  cookie[:value] = value
  cookie[:expires] += Time.now.to_i if cookie[:expires]
  @cookies[key] = cookie
  super
end