summary refs log tree commit
diff options
context:
space:
mode:
authorMax Cantor <max@maxcantor.net>2014-06-27 15:56:50 -0400
committerJames Tucker <jftucker@gmail.com>2014-07-13 16:17:41 -0700
commit704be37eeafa748141008418d7fcae49bcbae421 (patch)
tree58c1cd24ce54d6b7d08f6a14f9a2b0c01135372a
parent52a80a79e27d171af3ab7e604f9bc211bc9e3e80 (diff)
downloadrack-704be37eeafa748141008418d7fcae49bcbae421.tar.gz
Simplify default middleware construction.
- Removed concat, the DRYness isn't worth the loss of clarity.
- Removed ||=, no need to memoize such a small operation.
- Removed the array-default hash usage; if this behavior is supported,
  we should add a test for it.
-rw-r--r--lib/rack/server.rb20
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/rack/server.rb b/lib/rack/server.rb
index 711071ca..872b0798 100644
--- a/lib/rack/server.rb
+++ b/lib/rack/server.rb
@@ -213,16 +213,21 @@ module Rack
       end
 
       def default_middleware_by_environment
-        @default_middleware_by_environment ||= begin
-          m = Hash.new {|h,k| h[k] = []}
-          m["deployment"].concat [
+        {
+          "deployment" => [
             [Rack::ContentLength],
             [Rack::Chunked],
             logging_middleware
-          ]
-          m["development"].concat m["deployment"] + [[Rack::ShowExceptions], [Rack::Lint]]
-          m
-        end
+          ],
+          "development" => [
+            [Rack::ContentLength],
+            [Rack::Chunked],
+            logging_middleware,
+            [Rack::ShowExceptions],
+            [Rack::Lint]
+          ],
+          "none" => []
+        }
       end
 
       # Aliased for backwards-compatibility
@@ -317,6 +322,7 @@ module Rack
       def build_app(app)
         middlewares = default_middleware_by_environment[options[:environment]]
         middlewares.reverse_each do |middleware|
+          # these 2 lines specifically for Rack::Server.logging_middleware
           middleware = middleware.call(self) if middleware.respond_to?(:call)
           next unless middleware
           klass, *args = middleware