Class: Archipelago::Hashish::BerkeleyHashishProvider
- Inherits:
-
Object
- Object
- Archipelago::Hashish::BerkeleyHashishProvider
- Defined in:
- lib/archipelago/hashish.rb
Overview
A simple persistence provider backed by Berkeley db.
Instance Method Summary collapse
-
#get_cached_hashish(name) ⇒ Object
Returns a cleverly cached (but slightly inefficient) hash-like instance (see Archipelago::Hashish::BerkeleyHashish) using
name
. -
#get_hashish(name) ⇒ Object
Returns a normal hash-like instance using
name
. -
#initialize(env_path) ⇒ BerkeleyHashishProvider
constructor
Initialize an instance with the given
env_path
to its database dir. -
#unlink ⇒ Object
Closes databases opened by this instance and removes the persistent files.
Constructor Details
#initialize(env_path) ⇒ BerkeleyHashishProvider
Initialize an instance with the given env_path
to its database dir.
220 221 222 223 224 225 |
# File 'lib/archipelago/hashish.rb', line 220 def initialize(env_path) env_path.mkpath @env = BDB::Env.open(env_path, BDB::CREATE | BDB::INIT_MPOOL) @berkeley_hashishes = [] @bdb_dbs = [] end |
Instance Method Details
#get_cached_hashish(name) ⇒ Object
Returns a cleverly cached (but slightly inefficient) hash-like instance (see Archipelago::Hashish::BerkeleyHashish) using name
.
231 232 233 234 235 |
# File 'lib/archipelago/hashish.rb', line 231 def get_cached_hashish(name) hashish = BerkeleyHashish.new(name, @env) @berkeley_hashishes << hashish return hashish end |
#get_hashish(name) ⇒ Object
Returns a normal hash-like instance using name
.
239 240 241 242 243 |
# File 'lib/archipelago/hashish.rb', line 239 def get_hashish(name) db = @env.open_db(BDB::HASH, name, nil, BDB::CREATE | BDB::NOMMAP) @bdb_dbs << db return db end |
#unlink ⇒ Object
Closes databases opened by this instance and removes the persistent files.
247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/archipelago/hashish.rb', line 247 def unlink @berkeley_hashishes.each do |h| h.close! end @bdb_dbs.each do |d| d.close end home = Pathname.new(@env.home) @env.close home.rmtree if home.exist? end |