summary refs log tree commit
diff options
context:
space:
mode:
authorGraham Batty <graham@graham-battys-macbook.local>2009-02-26 16:51:56 -0700
committerMichael Fellinger <m.fellinger@gmail.com>2009-03-26 14:57:06 +0900
commit8a7b7ff0f44dad509ea605e023129cf630d9d5c6 (patch)
tree0f4c65fdae9c020392cea8b3f99d3e610c50d46f
parenta38920c3d459f2a83a7799828d2d3a2257b9d891 (diff)
downloadrack-8a7b7ff0f44dad509ea605e023129cf630d9d5c6.tar.gz
Simplified options for unregistered handlers
Made it so that it only accepts FullyCapsedClassNames for unregistered handlers as per suggestions in #rack irc channel.

Signed-off-by: Michael Fellinger <m.fellinger@gmail.com>
-rw-r--r--lib/rack/handler.rb21
-rw-r--r--test/spec_rack_handler.rb6
-rw-r--r--test/unregistered_handler/rack/handler/unregisteredlongtwo.rb7
3 files changed, 6 insertions, 28 deletions
diff --git a/lib/rack/handler.rb b/lib/rack/handler.rb
index ab7f0462..9f666a67 100644
--- a/lib/rack/handler.rb
+++ b/lib/rack/handler.rb
@@ -18,25 +18,14 @@ module Rack
       else
         # try to require the matching rack handler file (presumably from another gem)
         # the next couple of parts attempt to manipulate a proper constant name into
-        # a proper filename. BlahBlahBlorp -> either blah_blah_blorp or blahblahblorp.
+        # a proper filename. BlahBlahBlorp -> blah_blah_blorp
         begin
-          # first try blahblahblorp from BlahBlahBlorp (this is the cheaper case, so do it first)
-          require 'rack/handler/' + server.downcase
+          # next try and find blah_blorp_bloop from BlahBlorpBloop
+          require 'rack/handler/' + server.gsub(/^[A-Z]/) {|a| a.downcase }.gsub(/[A-Z]/) {|a| "_#{a.downcase}" }
         rescue LoadError
-          begin
-            # next try and find blah_blorp_bloop from BlahBlorpBloop
-            require 'rack/handler/' + server.gsub(/^[A-Z]/) {|a| a.downcase }.gsub(/[A-Z]/) {|a| "_#{a.downcase}" }
-          rescue LoadError
-            begin
-              require 'rack/handler/' + server.gsub(/_/, '')
-            rescue LoadError
-              # ignore it, move on and fail later.
-            end
-          end
+          # ignore it, move on and fail later.
         end
-        # Now try to const_get the handler in question after properly capitalizing it.
-        # blah_blah_blorp -> BlahBlahBlorp
-        return Rack::Handler.const_get(server.gsub(/(^|_)([a-z])/) {|a| $2.upcase })
+        return Rack::Handler.const_get(server)
       end
     end
 
diff --git a/test/spec_rack_handler.rb b/test/spec_rack_handler.rb
index 9b20b8ef..fcf19b78 100644
--- a/test/spec_rack_handler.rb
+++ b/test/spec_rack_handler.rb
@@ -20,7 +20,7 @@ context "Rack::Handler" do
   end
 
   specify "should get unregistered, but already required, handler by name" do
-    Rack::Handler.get('lobster').should.equal Rack::Handler::Lobster
+    Rack::Handler.get('Lobster').should.equal Rack::Handler::Lobster
   end
 
   specify "should register custom handler" do
@@ -31,15 +31,11 @@ context "Rack::Handler" do
   specify "should not need registration for properly coded handlers even if not already required" do
     begin
       $:.push "test/unregistered_handler"
-      Rack::Handler.get('unregistered').should.equal Rack::Handler::Unregistered
       Rack::Handler.get('Unregistered').should.equal Rack::Handler::Unregistered
       lambda {
         Rack::Handler.get('UnRegistered')
       }.should.raise(NameError)
-      Rack::Handler.get('unregistered_long_one').should.equal Rack::Handler::UnregisteredLongOne
       Rack::Handler.get('UnregisteredLongOne').should.equal Rack::Handler::UnregisteredLongOne
-      Rack::Handler.get('unregistered_long_two').should.equal Rack::Handler::UnregisteredLongTwo
-      Rack::Handler.get('UnregisteredLongTwo').should.equal Rack::Handler::UnregisteredLongTwo
     ensure
       $:.delete "test/unregistered_handler"
     end
diff --git a/test/unregistered_handler/rack/handler/unregisteredlongtwo.rb b/test/unregistered_handler/rack/handler/unregisteredlongtwo.rb
deleted file mode 100644
index 3c2e4b8d..00000000
--- a/test/unregistered_handler/rack/handler/unregisteredlongtwo.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-module Rack
-  module Handler
-    # this class doesn't do anything, we're just seeing if we get it.
-    class UnregisteredLongTwo
-    end
-  end
-end \ No newline at end of file