aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-05-29 22:29:14 +0200
committerMikel Lindsaar <raasdnil@gmail.com>2010-06-03 23:32:10 +1000
commit2740943634fe151fb3fb87e2af7881a93f5dd6b5 (patch)
tree4916366ccf706c49f7e2082a406a2a90471dff79 /actionpack/lib/action_dispatch
parent27939bd753b79c8205d1d3c1cdc7db6205642302 (diff)
downloadrails-2740943634fe151fb3fb87e2af7881a93f5dd6b5.tar.gz
rails-2740943634fe151fb3fb87e2af7881a93f5dd6b5.tar.bz2
rails-2740943634fe151fb3fb87e2af7881a93f5dd6b5.zip
Remove the laziness from the middleware stack.
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r--actionpack/lib/action_dispatch/middleware/stack.rb72
1 files changed, 15 insertions, 57 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/stack.rb b/actionpack/lib/action_dispatch/middleware/stack.rb
index 5c5362ce4a..0e5ab507df 100644
--- a/actionpack/lib/action_dispatch/middleware/stack.rb
+++ b/actionpack/lib/action_dispatch/middleware/stack.rb
@@ -3,49 +3,15 @@ require "active_support/inflector/methods"
module ActionDispatch
class MiddlewareStack < Array
class Middleware
- def self.new(klass, *args, &block)
- if klass.is_a?(self)
- klass
- else
- super
- end
- end
-
attr_reader :args, :block
def initialize(klass, *args, &block)
- @klass = klass
-
- options = args.extract_options!
- if options.has_key?(:if)
- @conditional = options.delete(:if)
- else
- @conditional = true
- end
- args << options unless options.empty?
-
- @args = args
- @block = block
+ @klass, @args, @block = klass, args, block
end
def klass
- if @klass.respond_to?(:new)
- @klass
- elsif @klass.respond_to?(:call)
- @klass.call
- else
- ActiveSupport::Inflector.constantize(@klass.to_s)
- end
- end
-
- def active?
- return false unless klass
-
- if @conditional.respond_to?(:call)
- @conditional.call
- else
- @conditional
- end
+ return @klass if @klass.respond_to?(:new)
+ @klass = ActiveSupport::Inflector.constantize(@klass.to_s)
end
def ==(middleware)
@@ -58,7 +24,7 @@ module ActionDispatch
if lazy_compare?(@klass) && lazy_compare?(middleware)
normalize(@klass) == normalize(middleware)
else
- klass.name == middleware.to_s
+ klass.name == normalize(middleware.to_s)
end
end
end
@@ -68,25 +34,18 @@ module ActionDispatch
end
def build(app)
- if block
- klass.new(app, *build_args, &block)
- else
- klass.new(app, *build_args)
- end
+ klass.new(app, *args, &block)
end
- private
- def lazy_compare?(object)
- object.is_a?(String) || object.is_a?(Symbol)
- end
+ private
- def normalize(object)
- object.to_s.strip.sub(/^::/, '')
- end
+ def lazy_compare?(object)
+ object.is_a?(String) || object.is_a?(Symbol)
+ end
- def build_args
- Array(args).map { |arg| arg.respond_to?(:call) ? arg.call : arg }
- end
+ def normalize(object)
+ object.to_s.strip.sub(/^::/, '')
+ end
end
def initialize(*args, &block)
@@ -119,15 +78,14 @@ module ActionDispatch
end
def active
- find_all { |middleware| middleware.active? }
+ ActiveSupport::Deprecation.warn "All middlewares in the chaing are active since the laziness " <<
+ "was removed from the middleware stack", caller
end
def build(app = nil, &blk)
app ||= blk
-
raise "MiddlewareStack#build requires an app" unless app
-
- active.reverse.inject(app) { |a, e| e.build(a) }
+ reverse.inject(app) { |a, e| e.build(a) }
end
end
end