From df91c57c312bee97a16bced1035bd704e518ac38 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 23 Nov 2010 12:09:56 -0800 Subject: rename internal "TokyoCabinet" => "TC" It's less typing and less likely to clash on both the eyes and the interpreter. --- lib/metropolis/tc/hdb/ro.rb | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 lib/metropolis/tc/hdb/ro.rb (limited to 'lib/metropolis/tc/hdb/ro.rb') diff --git a/lib/metropolis/tc/hdb/ro.rb b/lib/metropolis/tc/hdb/ro.rb new file mode 100644 index 0000000..f348ee4 --- /dev/null +++ b/lib/metropolis/tc/hdb/ro.rb @@ -0,0 +1,34 @@ +# -*- encoding: binary -*- + +module Metropolis::TC::HDB::RO + def self.extended(obj) + obj.instance_eval do + @wr_flags = nil + @rd_flags |= TokyoCabinet::HDB::ONOLCK + @dbv.each { |(hdb, path)| + hdb.open(path, @rd_flags) or ex!(:open, path) + } + @ro_dbv = @dbv.map { |(hdb,_)| hdb } + end + end + + def call(env) + if %r{\A/(.*)\z} =~ env["PATH_INFO"] + key = unescape($1) + case env["REQUEST_METHOD"] + when "GET" + get(key) + when "HEAD" + head(key) + else + [ 405, {}, [] ] + end + else # OPTIONS + [ 405, {}, [] ] + end + end + + def reader(key) + yield @ro_dbv[key.hash % @nr_slots] + end +end -- cgit v1.2.3-24-ge0c7