Class: Moneta::Adapters::Cookie
- Defined in:
- lib/moneta/adapters/cookie.rb
Overview
Cookie backend used by the middleware ‘Rack::MonetaCookies`
Instance Attribute Summary collapse
- #cookies ⇒ Object readonly
Instance Method Summary collapse
-
#clear(options = {}) ⇒ void
Clear all keys in this store.
-
#delete(key, options = {}) ⇒ Object
Delete the key from the store and return the current value.
-
#initialize(options = {}) ⇒ Cookie
constructor
A new instance of Cookie.
-
#reset(cookies) ⇒ Object
Reset the cookie store This method is used by the middleware.
-
#store(key, value, options = {}) ⇒ Object
Store value with key.
Methods included from IncrementSupport
Methods included from HashAdapter
Methods included from Defaults
#[], #[]=, #close, #decrement, #fetch, #increment, #key?
Methods included from OptionSupport
#expires, #prefix, #raw, #with
Constructor Details
#initialize(options = {}) ⇒ Cookie
Returns a new instance of Cookie.
8 9 10 11 |
# File 'lib/moneta/adapters/cookie.rb', line 8 def initialize( = {}) super @options, @cookies = , {} end |
Instance Attribute Details
#cookies ⇒ Object (readonly)
6 7 8 |
# File 'lib/moneta/adapters/cookie.rb', line 6 def @cookies end |
Instance Method Details
#clear(options = {}) ⇒ void
This method returns an undefined value.
Clear all keys in this store
29 30 31 32 33 |
# File 'lib/moneta/adapters/cookie.rb', line 29 def clear( = {}) @hash.each_key { |key| @cookies[key] = nil } super self end |
#delete(key, options = {}) ⇒ Object
Delete the key from the store and return the current value
23 24 25 26 |
# File 'lib/moneta/adapters/cookie.rb', line 23 def delete(key, = {}) @cookies[key] = nil super end |
#reset(cookies) ⇒ Object
Reset the cookie store This method is used by the middleware.
37 38 39 |
# File 'lib/moneta/adapters/cookie.rb', line 37 def reset() @cookies, @hash = {}, end |
#store(key, value, options = {}) ⇒ Object
Store value with key
14 15 16 17 18 19 20 |
# File 'lib/moneta/adapters/cookie.rb', line 14 def store(key, value, = {}) = @options.merge() [:value] = value [:expires] += Time.now.to_i if [:expires] @cookies[key] = super end |