From 2bb7406db018e6902aacaf495e63d69cf9b93174 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 23 Nov 2010 13:16:06 -0800 Subject: split out common read-only code It makes sense for other databases to share the same code. --- lib/metropolis/common.rb | 1 + lib/metropolis/common/ro.rb | 18 ++++++++++++++++++ lib/metropolis/tc/hdb/ro.rb | 18 ++---------------- 3 files changed, 21 insertions(+), 16 deletions(-) create mode 100644 lib/metropolis/common/ro.rb (limited to 'lib') diff --git a/lib/metropolis/common.rb b/lib/metropolis/common.rb index c4efcf3..738a511 100644 --- a/lib/metropolis/common.rb +++ b/lib/metropolis/common.rb @@ -1,6 +1,7 @@ # -*- encoding: binary -*- module Metropolis::Common include Rack::Utils # unescape + autoload :RO, 'metropolis/common/ro' def setup(opts) @uri = opts[:uri] diff --git a/lib/metropolis/common/ro.rb b/lib/metropolis/common/ro.rb new file mode 100644 index 0000000..10b5439 --- /dev/null +++ b/lib/metropolis/common/ro.rb @@ -0,0 +1,18 @@ +# -*- encoding: binary -*- +module Metropolis::Common::RO + 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 + r(403) + end + else # OPTIONS + r(405) + end + end +end diff --git a/lib/metropolis/tc/hdb/ro.rb b/lib/metropolis/tc/hdb/ro.rb index 4114606..fddd73c 100644 --- a/lib/metropolis/tc/hdb/ro.rb +++ b/lib/metropolis/tc/hdb/ro.rb @@ -1,6 +1,8 @@ # -*- encoding: binary -*- module Metropolis::TC::HDB::RO + include Metropolis::Common::RO + def self.extended(obj) obj.instance_eval do @wr_flags = nil @@ -12,22 +14,6 @@ module Metropolis::TC::HDB::RO 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 - r(403) - end - else # OPTIONS - r(405) - end - end - def reader(key) yield @ro_dbv[key.hash % @nr_slots] end -- cgit v1.2.3-24-ge0c7