Module: Moneta::DBMAdapter Private
- Includes:
- HashAdapter
- Included in:
- Adapters::DBM, Adapters::Daybreak, Adapters::GDBM, Adapters::SDBM
- Defined in:
- lib/moneta/dbm_adapter.rb
Overview
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.
This is for adapters that conform to the DBM interface
Instance Attribute Summary
Attributes included from HashAdapter
Instance Method Summary collapse
-
#close ⇒ Object
Explicitly close the store.
-
#merge!(pairs, options = {}) ⇒ Object
Stores the pairs in the key-value store, and returns itself.
Methods included from HashAdapter
#clear, #delete, #fetch_values, #key?, #load, #slice, #store, #values_at
Instance Method Details
#close ⇒ Object
Explicitly close the store
8 9 10 11 |
# File 'lib/moneta/dbm_adapter.rb', line 8 def close @backend.close nil end |
#merge!(pairs, options = {}) ⇒ self #merge!(pairs, options = {}) {|key, old_value, new_value| ... } ⇒ self
Some adapters may implement this method atomically, or in two passes when a block is provided. The default implmentation uses HashAdapter#key?, HashAdapter#load and HashAdapter#store.
Stores the pairs in the key-value store, and returns itself. When a block is provided, it will be called before overwriting any existing values with the key, old value and supplied value, and the return value of the block will be used in place of the supplied value.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/moneta/dbm_adapter.rb', line 14 def merge!(pairs, = {}) hash = if block_given? keys = pairs.map { |k, _| k } old_pairs = Hash[slice(*keys)] Hash[pairs.map do |key, new_value| new_value = yield(key, old_pairs[key], new_value) if old_pairs.key?(key) [key, new_value] end.to_a] else Hash === pairs ? pairs : Hash[pairs.to_a] end @backend.update(hash) self end |