diff options
-rw-r--r-- | lib/metropolis/common.rb | 1 | ||||
-rw-r--r-- | lib/metropolis/common/ro.rb | 18 | ||||
-rw-r--r-- | lib/metropolis/tc/hdb/ro.rb | 18 |
3 files changed, 21 insertions, 16 deletions
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 |