Module: Moneta::IncrementSupport Private
- Included in:
- Adapters::DBM, Adapters::Daybreak, Adapters::GDBM, Adapters::LRUHash, Adapters::LevelDB, Adapters::Memory, Adapters::SDBM, Adapters::Sqlite, Adapters::TDB, Adapters::TokyoCabinet, WeakIncrement
- Defined in:
- lib/moneta/increment_support.rb
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Class Method Summary collapse
- .included(base) ⇒ Object private
Instance Method Summary collapse
-
#increment(key, amount = 1, options = {}) ⇒ Object
Atomically increment integer value with key.
Class Method Details
.included(base) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 |
# File 'lib/moneta/increment_support.rb', line 12 def self.included(base) base.supports(:increment) if base.respond_to?(:supports) end |
Instance Method Details
#increment(key, amount = 1, options = {}) ⇒ Object
Note:
Not every Moneta store implements this method, a NotImplementedError is raised if it is not supported.
Atomically increment integer value with key
This method also accepts negative amounts.
5 6 7 8 9 10 |
# File 'lib/moneta/increment_support.rb', line 5 def increment(key, amount = 1, = {}) existing = load(key, ) value = (existing == nil ? 0 : Integer(existing)) + amount store(key, value.to_s, ) value end |