Class: Moneta::Adapters::Cookie
- Inherits:
-
Memory
- Object
- Moneta::Adapter
- Memory
- 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
Attributes included from HashAdapter
Attributes inherited from Moneta::Adapter
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 EachKeySupport
Methods included from CreateSupport
Methods included from IncrementSupport
Methods included from HashAdapter
#fetch_values, #key?, #load, #merge!, #slice, #values_at
Methods included from NilValues
#fetch_values, #merge!, #slice
Methods inherited from Moneta::Adapter
backend, backend_block, backend_required?
Methods included from Config
Methods included from Defaults
#[], #[]=, #close, #create, #decrement, #each_key, #features, #fetch, #fetch_values, included, #increment, #key?, #merge!, #slice, #supports?, #update, #values_at
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( = {}) @backend.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, @backend = {}, 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 |