Class: Moneta::Stack
Overview
Combines multiple stores. Reads return the result from the first store, writes go to all stores.
Defined Under Namespace
Classes: DSL
Instance Attribute Summary collapse
- #stack ⇒ Object readonly
Instance Method Summary collapse
-
#clear(options = {}) ⇒ void
Clear all keys in this store.
- #close ⇒ Object
- #create(key, value, options = {}) ⇒ Object
-
#delete(key, options = {}) ⇒ Object
Delete the key from the store and return the current value.
- #features ⇒ Object
- #increment(key, amount = 1, options = {}) ⇒ Object
-
#initialize(options = {}) {|Builder| ... } ⇒ Stack
constructor
A new instance of Stack.
- #key?(key, options = {}) ⇒ Boolean
-
#load(key, options = {}) ⇒ Object
Fetch value with key.
-
#store(key, value, options = {}) ⇒ Object
Store value with key.
Methods included from Defaults
#[], #[]=, #decrement, #each_key, #fetch, #fetch_values, included, #merge!, #slice, #supports?, #update, #values_at
Methods included from OptionSupport
#expires, #prefix, #raw, #with
Constructor Details
Instance Attribute Details
#stack ⇒ Object (readonly)
33 34 35 |
# File 'lib/moneta/stack.rb', line 33 def stack @stack end |
Instance Method Details
#clear(options = {}) ⇒ void
This method returns an undefined value.
Clear all keys in this store
86 87 88 89 |
# File 'lib/moneta/stack.rb', line 86 def clear( = {}) @stack.each { |s| s.clear() } self end |
#close ⇒ Object
92 93 94 95 |
# File 'lib/moneta/stack.rb', line 92 def close @stack.each { |s| s.close } nil end |
#create(key, value, options = {}) ⇒ Object
71 72 73 74 75 |
# File 'lib/moneta/stack.rb', line 71 def create(key, value, = {}) last = false @stack.each { |s| last = s.create(key, value, ) } last end |
#delete(key, options = {}) ⇒ Object
Delete the key from the store and return the current value
78 79 80 81 82 83 |
# File 'lib/moneta/stack.rb', line 78 def delete(key, = {}) @stack.inject(nil) do |value, s| v = s.delete(key, ) value || v end end |
#features ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/moneta/stack.rb', line 98 def features @features ||= begin features = @stack.map(&:features) (features.inject(features.first, &:&) - [:each_key]).freeze end end |
#increment(key, amount = 1, options = {}) ⇒ Object
64 65 66 67 68 |
# File 'lib/moneta/stack.rb', line 64 def increment(key, amount = 1, = {}) last = nil @stack.each { |s| last = s.increment(key, amount, ) } last end |
#key?(key, options = {}) ⇒ Boolean
44 45 46 |
# File 'lib/moneta/stack.rb', line 44 def key?(key, = {}) @stack.any? { |s| s.key?(key, ) } end |
#load(key, options = {}) ⇒ Object
Fetch value with key. Return nil if the key doesn’t exist
49 50 51 52 53 54 55 |
# File 'lib/moneta/stack.rb', line 49 def load(key, = {}) @stack.each do |s| value = s.load(key, ) return value if value != nil end nil end |
#store(key, value, options = {}) ⇒ Object
Store value with key
58 59 60 61 |
# File 'lib/moneta/stack.rb', line 58 def store(key, value, = {}) @stack.each { |s| s.store(key, value, ) } value end |