diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-11-23 12:09:56 -0800 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-11-23 12:09:56 -0800 |
commit | df91c57c312bee97a16bced1035bd704e518ac38 (patch) | |
tree | 0678c58830c09e9a8e0de92a33fa078f2445ee4e /lib/metropolis/tc/hdb/ro.rb | |
parent | 51d43461adca99482154ddbd337658a70d5ffc3d (diff) | |
download | metropolis-df91c57c312bee97a16bced1035bd704e518ac38.tar.gz |
rename internal "TokyoCabinet" => "TC"
It's less typing and less likely to clash on both the eyes and the interpreter.
Diffstat (limited to 'lib/metropolis/tc/hdb/ro.rb')
-rw-r--r-- | lib/metropolis/tc/hdb/ro.rb | 34 |
1 files changed, 34 insertions, 0 deletions
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 |