Flay Report said, i have duplication in my code
This commit is contained in:
parent
f04fcac66d
commit
b9d52726ae
|
@ -16,4 +16,10 @@ module SBDB
|
||||||
def queue( *p) Queue.new *p end
|
def queue( *p) Queue.new *p end
|
||||||
def unknown( *p) Unknown.new *p end
|
def unknown( *p) Unknown.new *p end
|
||||||
alias open_db unknown
|
alias open_db unknown
|
||||||
|
|
||||||
|
def raise_barrier *ps, &e
|
||||||
|
e.call *ps
|
||||||
|
rescue Object
|
||||||
|
$stderr.puts [$!.class,$!,$!.backtrace].inspect
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,20 +46,14 @@ module SBDB
|
||||||
alias del delete
|
alias del delete
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def new *p, &e
|
def new *ps, &exe
|
||||||
x = super *p
|
ret = obj = super( *ps)
|
||||||
return x unless e
|
begin ret = e.call obj
|
||||||
begin e.call x
|
|
||||||
ensure
|
ensure
|
||||||
begin x.sync
|
SBDB::raise_barrier obj.method(:sync)
|
||||||
rescue Object
|
SBDB::raise_barrier obj.method(:close)
|
||||||
$stderr.puts [$!.class,$!,$!.backtrace].inspect
|
end if exe
|
||||||
end
|
ret
|
||||||
begin x.close
|
|
||||||
rescue Object
|
|
||||||
$stderr.puts [$!.class,$!,$!.backtrace].inspect
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
alias open new
|
alias open new
|
||||||
end
|
end
|
||||||
|
@ -119,7 +113,7 @@ module SBDB
|
||||||
end
|
end
|
||||||
TYPES[DB::HASH] = Hash
|
TYPES[DB::HASH] = Hash
|
||||||
|
|
||||||
class Recno < DB
|
module Arrayisch
|
||||||
def [] k
|
def [] k
|
||||||
super [k].pack('I')
|
super [k].pack('I')
|
||||||
end
|
end
|
||||||
|
@ -132,25 +126,18 @@ module SBDB
|
||||||
@db.put _txn(txn), "\0\0\0\0", v, Bdb::DB_APPEND
|
@db.put _txn(txn), "\0\0\0\0", v, Bdb::DB_APPEND
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class Recno < DB
|
||||||
|
extend Arrayisch
|
||||||
|
end
|
||||||
Array = Recno
|
Array = Recno
|
||||||
TYPES[DB::RECNO] = Recno
|
TYPES[DB::RECNO] = Recno
|
||||||
|
|
||||||
class Queue < DB
|
class Queue < Arrayisch
|
||||||
def [] k
|
extend Arrayisch
|
||||||
super [k].pack('I')
|
|
||||||
end
|
|
||||||
|
|
||||||
def []= k, v
|
|
||||||
super [k].pack('I'), v
|
|
||||||
end
|
|
||||||
|
|
||||||
def unshift txn = nil
|
def unshift txn = nil
|
||||||
@db.get _txn(txn), "\0\0\0\0", nil, Bdb::DB_CONSUME
|
@db.get _txn(txn), "\0\0\0\0", nil, Bdb::DB_CONSUME
|
||||||
end
|
end
|
||||||
|
|
||||||
def push v, txn = nil
|
|
||||||
@db.put _txn(txn), "\0\0\0\0", v, Bdb::DB_APPEND
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
TYPES[DB::QUEUE] = Queue
|
TYPES[DB::QUEUE] = Queue
|
||||||
end
|
end
|
||||||
|
|
|
@ -75,11 +75,7 @@ module SBDB
|
||||||
def self.new *args
|
def self.new *args
|
||||||
obj = r = super( *args)
|
obj = r = super( *args)
|
||||||
begin r = yield obj
|
begin r = yield obj
|
||||||
ensure
|
ensure SBDB::raise_barrier obj.method(:close)
|
||||||
begin obj.close
|
|
||||||
rescue Object
|
|
||||||
$stderr.puts [$!.class,$!,$!.backtrace].inspect
|
|
||||||
end
|
|
||||||
end if block_given?
|
end if block_given?
|
||||||
r
|
r
|
||||||
end
|
end
|
||||||
|
@ -112,9 +108,10 @@ module SBDB
|
||||||
def [] file, *p, &e
|
def [] file, *p, &e
|
||||||
p.push ::Hash.new unless ::Hash === p.last
|
p.push ::Hash.new unless ::Hash === p.last
|
||||||
p.last[:env] = self
|
p.last[:env] = self
|
||||||
name = String === p[0] ? p[0] : p.last[:name]
|
name, flags, type =
|
||||||
flags = Fixnum === p[1] ? p[1] : p.last[:flags]
|
String === p[0] ? p[0] : p.last[:name],
|
||||||
type = Fixnum === p[2] ? p[2] : p.last[:type]
|
Fixnum === p[1] ? p[1] : p.last[:flags],
|
||||||
|
Fixnum === p[2] ? p[2] : p.last[:type]
|
||||||
@dbs[ [file, name, flags | CREATE]] ||= (type || SBDB::Unknown).new file, *p, &e
|
@dbs[ [file, name, flags | CREATE]] ||= (type || SBDB::Unknown).new file, *p, &e
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue