about summary refs log tree commit
path: root/lib/metropolis.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-12-06 15:43:46 -0800
committerEric Wong <normalperson@yhbt.net>2010-12-06 15:43:46 -0800
commit88fa90b7f039f62962cc8d11031446412b951be2 (patch)
tree04c2d961f6e3e41b069f074d7b93e1d91d8d716e /lib/metropolis.rb
parent74ca34be2d54809822447ff185d88d83fcd566ae (diff)
downloadmetropolis-88fa90b7f039f62962cc8d11031446412b951be2.tar.gz
allow easier, single-file options for TC and TDB
Most (other) users only need a single file, even though
my primary use of this is for multiple files.
Diffstat (limited to 'lib/metropolis.rb')
-rw-r--r--lib/metropolis.rb30
1 files changed, 12 insertions, 18 deletions
diff --git a/lib/metropolis.rb b/lib/metropolis.rb
index 425ce1c..c38d4af 100644
--- a/lib/metropolis.rb
+++ b/lib/metropolis.rb
@@ -13,28 +13,22 @@ module Metropolis
   def self.new(opts = {})
     opts = opts.dup
     rv = Object.new
-    uri = opts[:uri] = URI.parse(opts[:uri])
-    if uri.path != '/' && opts[:path_pattern]
-      raise ArgumentError, ":path_pattern may only be used if path is '/'"
+    uri = URI.parse(opts[:uri])
+    rv.instance_eval do
+      @uri = uri
+      @query = @uri.query ? Rack::Utils.parse_query(@uri.query) : nil
+      @path_pattern = opts[:path_pattern]
+      @path = @uri.path if @uri.path != '/'
     end
-    case uri.scheme
-    when 'hash'
-      opts[:path] = uri.path if uri.path != '/'
-      rv.extend Metropolis::Hash
-    when 'tdb'
-      opts[:query] = Rack::Utils.parse_query(uri.query) if uri.query
-      rv.extend Metropolis::TDB
-    when 'tc'
-      opts[:query] = Rack::Utils.parse_query(uri.query) if uri.query
-      case ext = File.extname(opts[:path_pattern] || uri.path)
-      when '.tch'
-        rv.extend Metropolis::TC::HDB
-      else
-        raise ArgumentError, "unsupported suffix: #{ext}"
-      end
+
+    base = case uri.scheme
+    when 'hash' then Metropolis::Hash
+    when 'tdb' then Metropolis::TDB
+    when 'tc' then Metropolis::TC
     else
       raise ArgumentError, "unsupported URI scheme: #{uri.scheme}"
     end
+    rv.extend(base)
     rv.setup(opts)
     rv
   end