allow easier, single-file options for TC and TDB
[metropolis.git] / lib / metropolis / tdb / multi.rb
blobb22e63bf7a1f8b8b57b26bc23f84511314f9795e
1 # -*- encoding: binary -*-
2 module Metropolis::TDB::Multi
3   def self.extended(obj)
4     obj.instance_eval do
5       @dbv = (0...@nr_slots).to_a.map do |slot|
6         path = sprintf(@path_pattern, slot)
7         ::TDB.new(path, @tdb_opts)
8       end
9     end
10   end
12   def db(key, &block)
13     yield @dbv[key.hash % @nr_slots]
14   end
16   def close!
17     @dbv.each { |tdb| tdb.close }
18   end
19 end