class BioLocus::TokyoCabinetMapper

Public Class Methods

new(dbname) click to toggle source
# File lib/bio-locus/dbmapper.rb, line 50
def initialize dbname
  begin
    require 'tokyocabinet'
  rescue LoadError
    $stderr.print "Error: Missing tokyocabinet. Install with command 'gem install tokyocabinet'\n"
    exit 1
  end
  @hdb = TokyoCabinet::HDB::new
  if File.exist?(dbname)
    if !@hdb.open(dbname, TokyoCabinet::HDB::OREADER)
      ecode = @hdb.ecode
      raise sprintf("open error: %s\n", @hdb.errmsg(ecode))
    end
  else
    if !@hdb.open(dbname, TokyoCabinet::HDB::OWRITER | TokyoCabinet::HDB::OCREAT)
      ecode = @hdb.ecode
      raise sprintf("open error: %s\n", @hdb.errmsg(ecode))
    end
  end
end

Public Instance Methods

[](key) click to toggle source
# File lib/bio-locus/dbmapper.rb, line 71
def [] key
  @hdb.get(key)
end
[]=(key, value) click to toggle source
# File lib/bio-locus/dbmapper.rb, line 75
def []= key, value
  if !@hdb.put(key,value) 
    ecode = @hdb.ecode
    raise sprintf("put error: %s\n", @hdb.errmsg(ecode))
  end
end
close() click to toggle source
# File lib/bio-locus/dbmapper.rb, line 82
def close
  if !@hdb.close
    ecode = @hdb.ecode
    raise sprintf("close error: %s\n", @hdb.errmsg(ecode))
  end
end