module Persist::CDBAdapter
Public Class Methods
Source
# File lib/rbbt/persist/tsv/cdb.rb, line 8 def self.open(path, write) write = true unless File.exist? path database = CONNECTIONS[path] ||= begin file = File.open(path, 'w') LibCDB::CDB.new(file) end database.extend Persist::CDBAdapter unless Persist::CDBAdapter === database database.persistence_path ||= path database end
Public Instance Methods
Source
# File lib/rbbt/persist/tsv/cdb.rb, line 30 def [](*args) write? ? nil : super(*args) end
Calls superclass method
Persist::TSVAdapter#[]
Source
# File lib/rbbt/persist/tsv/cdb.rb, line 34 def []=(k,v) if write? add(k,v) end end
Source
# File lib/rbbt/persist/tsv/cdb.rb, line 51 def close self.closed = true begin fix_io super rescue end end
Calls superclass method
Persist::TSVAdapter#close
Source
# File lib/rbbt/persist/tsv/cdb.rb, line 44 def fix_io ddd instance_variable_get(:@io) if instance_variable_get(:@io) != persistence_path instance_variable_set(:@io, File.open(persistence_path)) end end
Source
# File lib/rbbt/persist/tsv/cdb.rb, line 26 def include?(k) not write? and super(k) end
Calls superclass method
Persist::TSVAdapter#include?
Source
# File lib/rbbt/persist/tsv/cdb.rb, line 115 def merge!(hash) hash.each do |key,values| self[key] = values end end
Source
# File lib/rbbt/persist/tsv/cdb.rb, line 122 def range(*args) super(*args) - TSV::ENTRY_KEYS.to_a end
Calls superclass method
Persist::TSVAdapter#range
Source
# File lib/rbbt/persist/tsv/cdb.rb, line 60 def read(force = false) self.closed = false fix_io open_read end
Source
# File lib/rbbt/persist/tsv/cdb.rb, line 105 def read_and_close read if @closed or write? res = begin yield ensure close end res end
Source
# File lib/rbbt/persist/tsv/cdb.rb, line 66 def write(force = true) self.closed = false fix_io open_write self end
Source
# File lib/rbbt/persist/tsv/cdb.rb, line 92 def write_and_close lock_filename = Persist.persistence_path(persistence_path, {:dir => TSV.lock_dir}) Misc.lock(lock_filename) do write if @closed or not write? res = begin yield ensure close end res end end
Source
# File lib/rbbt/persist/tsv/cdb.rb, line 77 def write_and_read lock_filename = Persist.persistence_path(persistence_path, {:dir => TSV.lock_dir}) Misc.lock(lock_filename) do write if @closed or not write? res = begin yield rescue Log.error $!.message Log.debug $!.backtrace * "\n" ensure read if write? end end end