Class: LevelDBNative::DB
- Inherits:
-
Object
- Object
- LevelDBNative::DB
- Includes:
- Enumerable
- Defined in:
- lib/leveldb-native.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#pathname ⇒ Object
readonly
Returns the value of attribute pathname.
Class Method Summary collapse
-
.create(pathname, options = {}) ⇒ Object
Creates a new database stored on disk at
pathname. -
.load(pathname) ⇒ Object
Loads a database stored on disk at
pathname. -
.new(pathname, options = {}) ⇒ Object
Loads or creates a database as necessary, stored on disk at
pathname.
Instance Method Summary collapse
- #each(*args, &block) ⇒ Object
- #inspect ⇒ Object
- #iterator(*args) ⇒ Object
- #keys ⇒ Object
-
#snapshot(*args) ⇒ Object
If called with a block, yields a snapshot to the caller, and the snapshot is released after the block finishes.
- #values ⇒ Object
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
44 45 46 |
# File 'lib/leveldb-native.rb', line 44 def end |
#pathname ⇒ Object (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, ={} make path_string(pathname), .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, ={} make path_string(pathname), .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 |
#inspect ⇒ Object
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 |
#keys ⇒ Object
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 |
#values ⇒ Object
61 |
# File 'lib/leveldb-native.rb', line 61 def values; map {|k, v| v} end |