Class: Moneta::Adapters::LevelDB

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

Overview

LevelDB backend

Instance Method Summary collapse

Methods included from IncrementSupport

#increment

Methods included from HashAdapter

#delete, #load, #store

Methods included from Defaults

#[], #[]=, #decrement, #fetch, #increment

Methods included from OptionSupport

#expires, #prefix, #raw, #with

Constructor Details

#initialize(options = {}) ⇒ LevelDB

Returns a new instance of LevelDB.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :dir (String)
    • Database path

  • All (Object)

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

Raises:

  • (ArgumentError)


11
12
13
14
# File 'lib/moneta/adapters/leveldb.rb', line 11

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

Instance Method Details

#clear(options = {}) ⇒ void

This method returns an undefined value.

Clear all keys in this store

Parameters:

  • options (Hash) (defaults to: {})


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

def clear(options = {})
  @hash.each {|k,v| delete(k, options) }
  self
end

#closeObject

Explicitly close the store

Returns:

  • nil



28
29
30
31
# File 'lib/moneta/adapters/leveldb.rb', line 28

def close
  @hash.close
  nil
end

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

Exists the value with key

Parameters:

  • key (Object)
  • options (Hash) (defaults to: {})

Returns:

  • (Boolean)


17
18
19
# File 'lib/moneta/adapters/leveldb.rb', line 17

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