about summary refs log tree commit
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-11-23 13:16:06 -0800
committerEric Wong <normalperson@yhbt.net>2010-11-23 13:16:06 -0800
commit2bb7406db018e6902aacaf495e63d69cf9b93174 (patch)
tree77777549533e40170772045fa5984b3a72038ff9
parent861f7759a53b37f76a9b64710b2312a1fd1365a8 (diff)
downloadmetropolis-2bb7406db018e6902aacaf495e63d69cf9b93174.tar.gz
split out common read-only code
It makes sense for other databases to share the same code.
-rw-r--r--lib/metropolis/common.rb1
-rw-r--r--lib/metropolis/common/ro.rb18
-rw-r--r--lib/metropolis/tc/hdb/ro.rb18
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