From a9d9aa36642cf74616f16351b86fffe590d94250 Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Mon, 29 Mar 2010 15:02:00 +0200 Subject: [PATCH] Env#[]: args should be the same like DB::initialize, now --- lib/sbdb/db.rb | 8 ++++++++ lib/sbdb/environment.rb | 10 ++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/sbdb/db.rb b/lib/sbdb/db.rb index 4ca1a86..260cf8e 100644 --- a/lib/sbdb/db.rb +++ b/lib/sbdb/db.rb @@ -63,6 +63,14 @@ module SBDB txn && t.bdb_object end + # Arguments: + # * file + # * name + # * type + # * flags + # * mode + # * env + # or: **file**, **opts**. *opts* must be a *::Hash* with keys like above, excluded *file*. def initialize file, *args opts = ::Hash === args.last ? args.pop : {} opts = {:name => args[0], :type => args[1], :flags => args[2], :mode => args[3], :env => args[4]}.update opts diff --git a/lib/sbdb/environment.rb b/lib/sbdb/environment.rb index 976bfe0..9a6479e 100644 --- a/lib/sbdb/environment.rb +++ b/lib/sbdb/environment.rb @@ -106,12 +106,10 @@ module SBDB # If you use this, never use close. It's possible somebody else use it too. # The Databases, which are opened, will close, if the Environment will close. def [] file, *ps, &exe - ps.push ::Hash.new unless ::Hash === ps.last - ps.last[:env] = self - name, flg, type = - String === ps[0] ? ps[0] : ps.last[:name], - Fixnum === ps[2] ? ps[2] : ps.last[:flags], - Fixnum === ps[1] ? ps[1] : ps.last[:type] + opts = ::Hash === ps.last ? ps.pop : {} + opts[:env] = self + name, type, flg = ps[0] || opts[:name], ps[1] || opts[:type], ps[2] || opts[:flags] + ps.push opts @dbs[ [file, name, flg | CREATE]] ||= (type || SBDB::Unknown).new file, *ps, &exe end end