Class: Moneta::Adapters::LevelDB
- Inherits:
-
Moneta::Adapter
- Object
- Moneta::Adapter
- Moneta::Adapters::LevelDB
- Includes:
- CreateSupport, EachKeySupport, HashAdapter, IncrementSupport
- Defined in:
- lib/moneta/adapters/leveldb.rb
Overview
LevelDB backend
Instance Attribute Summary
Attributes included from HashAdapter
Attributes inherited from Moneta::Adapter
Instance Method Summary collapse
-
#clear(options = {}) ⇒ void
Clear all keys in this store.
-
#close ⇒ Object
Explicitly close the store.
-
#each_key ⇒ Object
Calls block once for each key in store, passing the key as a parameter.
- #initialize(options = {}) ⇒ Object constructor
-
#key?(key, options = {}) ⇒ Boolean
Exists the value with key.
-
#merge!(*keys, **options) ⇒ Object
Stores the pairs in the key-value store, and returns itself.
-
#values_at(*keys, **options) ⇒ Array<Object, nil>
Returns an array containing the values associated with the given keys, in the same order as the supplied keys.
Methods included from EachKeySupport
Methods included from CreateSupport
Methods included from IncrementSupport
Methods included from HashAdapter
#delete, #fetch_values, #load, #slice, #store
Methods inherited from Moneta::Adapter
backend, backend_block, backend_required?
Methods included from Config
Methods included from Defaults
#[], #[]=, #create, #decrement, #features, #fetch, #fetch_values, included, #increment, #slice, #supports?, #update
Methods included from OptionSupport
#expires, #prefix, #raw, #with
Constructor Details
#initialize(options = {}) ⇒ Object
18 |
# File 'lib/moneta/adapters/leveldb.rb', line 18 backend { |dir:| ::LevelDB::DB.new(dir) } |
Instance Method Details
#clear(options = {}) ⇒ void
This method returns an undefined value.
Clear all keys in this store
26 27 28 29 |
# File 'lib/moneta/adapters/leveldb.rb', line 26 def clear( = {}) backend.each { |k,| delete(k, ) } self end |
#close ⇒ Object
Explicitly close the store
32 33 34 35 |
# File 'lib/moneta/adapters/leveldb.rb', line 32 def close backend.close nil end |
#each_key ⇒ Enumerator #each_key {|key| ... } ⇒ self
Not every Moneta store implements this method, a NotImplementedError is raised if it is not supported.
Calls block once for each key in store, passing the key as a parameter. If no block is given, an enumerator is returned instead.
38 39 40 41 42 |
# File 'lib/moneta/adapters/leveldb.rb', line 38 def each_key return enum_for(:each_key) { backend.size } unless block_given? backend.each { |key, _| yield key } self end |
#key?(key, options = {}) ⇒ Boolean
Exists the value with key
21 22 23 |
# File 'lib/moneta/adapters/leveldb.rb', line 21 def key?(key, = {}) backend.includes?(key) 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 #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.
52 53 54 55 |
# File 'lib/moneta/adapters/leveldb.rb', line 52 def merge!(*keys, **) backend.batch { super } self end |
#values_at(*keys, **options) ⇒ Array<Object, nil>
Some adapters may implement this method atomically, but the default implementation simply makes repeated calls to HashAdapter#load.
Returns an array containing the values associated with the given keys, in the same order as the supplied keys. If a key is not present in the key-value-store, nil is returned in its place.
45 46 47 48 49 |
# File 'lib/moneta/adapters/leveldb.rb', line 45 def values_at(*keys, **) ret = nil backend.batch { ret = super } ret end |