Class: BioLocus::TokyoCabinetMapper
- Inherits:
-
Object
- Object
- BioLocus::TokyoCabinetMapper
- Defined in:
- lib/bio-locus/dbmapper.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #close ⇒ Object
-
#initialize(dbname) ⇒ TokyoCabinetMapper
constructor
A new instance of TokyoCabinetMapper.
Constructor Details
#initialize(dbname) ⇒ TokyoCabinetMapper
Returns a new instance of TokyoCabinetMapper.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# 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 |
Instance Method Details
#[](key) ⇒ Object
71 72 73 |
# File 'lib/bio-locus/dbmapper.rb', line 71 def [] key @hdb.get(key) end |
#[]=(key, value) ⇒ Object
75 76 77 78 79 80 |
# 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 ⇒ Object
82 83 84 85 86 87 |
# 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 |