Module: Moneta::IncrementSupport Private
- Included in:
- Adapters::File, Adapters::LRUHash, Adapters::Memory, Adapters::Sqlite
- Defined in:
- lib/moneta/mixins.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.
Instance Method Summary collapse
-
#increment(key, amount = 1, options = {}) ⇒ Object
Atomically increment integer value with key.
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.
148 149 150 151 152 153 154 155 |
# File 'lib/moneta/mixins.rb', line 148 def increment(key, amount = 1, = {}) value = load(key, ) intvalue = value.to_i raise 'Tried to increment non integer value' unless value == nil || intvalue.to_s == value.to_s intvalue += amount store(key, intvalue.to_s, ) intvalue end |