Class: LevelDBNative::DB

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/leveldb-native.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



44
45
46
# File 'lib/leveldb-native.rb', line 44

def options
  @options
end

#pathnameObject (readonly)

Returns the value of attribute pathname.



43
44
45
# File 'lib/leveldb-native.rb', line 43

def pathname
  @pathname
end

Class Method Details

.create(pathname, options = {}) ⇒ Object

Creates a new database stored on disk at pathname. Raises LevelDBNative::Error if the database already exists.

See #make for possible options.



22
23
24
25
26
# File 'lib/leveldb-native.rb', line 22

def create pathname, options={}
  make path_string(pathname),
       options.merge(:create_if_missing => true,
                     :error_if_exists => true)
end

.load(pathname) ⇒ Object

Loads a database stored on disk at pathname. Raises LevelDBNative::Error unless the database already exists.



30
31
32
33
# File 'lib/leveldb-native.rb', line 30

def load pathname
  make path_string(pathname),
       :create_if_missing => false, :error_if_exists => false
end

.new(pathname, options = {}) ⇒ Object

Loads or creates a database as necessary, stored on disk at pathname.

See #make for possible options.



12
13
14
15
16
# File 'lib/leveldb-native.rb', line 12

def new pathname, options={}
  make path_string(pathname),
       options.merge(:create_if_missing => true,
                     :error_if_exists => false)
end

Instance Method Details

#each(*args, &block) ⇒ Object



53
54
55
56
57
# File 'lib/leveldb-native.rb', line 53

def each(*args, &block)
  i = iterator(*args)
  i.each(&block) if block
  i
end

#inspectObject



79
80
81
# File 'lib/leveldb-native.rb', line 79

def inspect
  "<#{self.class} #{@pathname.inspect}>"
end

#iterator(*args) ⇒ Object



59
# File 'lib/leveldb-native.rb', line 59

def iterator(*args); Iterator.new self, *args; end

#keysObject



60
# File 'lib/leveldb-native.rb', line 60

def keys; map {|k, v| k} end

#snapshot(*args) ⇒ Object

If called with a block, yields a snapshot to the caller, and the snapshot is released after the block finishes. Otherwise, returns a snapshot and caller must call #release on the snapshot.



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/leveldb-native.rb', line 66

def snapshot(*args)
  sn = Snapshot.new self, *args
  if block_given?
    begin
      yield sn
    ensure
      sn.release
    end
  else
    sn
  end
end

#valuesObject



61
# File 'lib/leveldb-native.rb', line 61

def values; map {|k, v| v} end