Class: Moneta::Adapters::LevelDB

Inherits:
Memory
  • Object
show all
Defined in:
lib/moneta/adapters/leveldb.rb

Overview

LevelDB backend

Instance Attribute Summary

Attributes included from HashAdapter

#backend

Instance Method Summary collapse

Methods included from CreateSupport

#create, included

Methods included from IncrementSupport

included, #increment

Methods included from HashAdapter

#delete, #load, #store

Methods included from Defaults

#[], #[]=, #create, #decrement, #features, #fetch, included, #increment, #supports?

Methods included from OptionSupport

#expires, #prefix, #raw, #with

Constructor Details

#initialize(options = {}) ⇒ LevelDB

Returns a new instance of LevelDB

Options Hash (options):

  • :dir (String)
    • Database path

  • All (Object)

    other options passed to `LevelDB::DB#new`

  • :backend (::LevelDB::DB)

    Use existing backend instance


12
13
14
15
16
17
18
# File 'lib/moneta/adapters/leveldb.rb', line 12

def initialize(options = {})
  @backend = options[:backend] ||
    begin
      raise ArgumentError, 'Option :dir is required' unless options[:dir]
      ::LevelDB::DB.new(options[:dir])
    end
end

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(options = {})
  @backend.each {|k,v| delete(k, options) }
  self
end

#closeObject

Explicitly close the store


32
33
34
35
# File 'lib/moneta/adapters/leveldb.rb', line 32

def close
  @backend.close
  nil
end

#key?(key, options = {}) ⇒ Boolean

Exists the value with key

Options Hash (options):

  • :expires (Integer)

    Update expiration time (See Expires)

  • :prefix (String)

    Prefix key (See Transformer)

  • Other (Object)

    options as defined by the adapters or middleware


21
22
23
# File 'lib/moneta/adapters/leveldb.rb', line 21

def key?(key, options = {})
  @backend.includes?(key)
end