class Anemone::Storage::TokyoCabinet

Public Class Methods

new(file) click to toggle source
# File lib/anemone/storage/tokyo_cabinet.rb, line 18
def initialize(file)
  raise "TokyoCabinet filename must have .tch extension" if File.extname(file) != '.tch'
  @db = ::TokyoCabinet::HDB::new
  @db.open(file, ::TokyoCabinet::HDB::OWRITER | ::TokyoCabinet::HDB::OCREAT)
  @db.clear
end

Public Instance Methods

[](key) click to toggle source
# File lib/anemone/storage/tokyo_cabinet.rb, line 25
def [](key)
  if value = @db[key]
    load_value(value)
  end
end
[]=(key, value) click to toggle source
# File lib/anemone/storage/tokyo_cabinet.rb, line 31
def []=(key, value)
  @db[key] = [Marshal.dump(value)].pack("m")
end
delete(key) click to toggle source
# File lib/anemone/storage/tokyo_cabinet.rb, line 35
def delete(key)
  value = self[key]
  @db.delete(key)
  value
end
each() { |k, self| ... } click to toggle source
# File lib/anemone/storage/tokyo_cabinet.rb, line 41
def each
  @db.keys.each do |k|
    yield(k, self[k])
  end
end
merge!(hash) click to toggle source
# File lib/anemone/storage/tokyo_cabinet.rb, line 47
def merge!(hash)
  hash.each { |key, value| self[key] = value }
  self
end

Private Instance Methods

load_value(value) click to toggle source
# File lib/anemone/storage/tokyo_cabinet.rb, line 54
def load_value(value)
  Marshal.load(value.unpack("m")[0])
end