aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Fuchs <svenfuchs@artweb-design.de>2009-02-20 10:50:21 -0600
committerJoshua Peek <josh@joshpeek.com>2009-02-20 10:50:21 -0600
commit53fe301a42f9d18b4a8a475e9babf64c621369ae (patch)
tree32ba2bc4e148c607bbdae56b74c3eb9c6762f86c
parent9702636a08e50e9fed9bf76ad620a6a0a109009e (diff)
downloadrails-53fe301a42f9d18b4a8a475e9babf64c621369ae.tar.gz
rails-53fe301a42f9d18b4a8a475e9babf64c621369ae.tar.bz2
rails-53fe301a42f9d18b4a8a475e9babf64c621369ae.zip
Lazy evaluate middleware arguments [#2028 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
-rw-r--r--actionpack/lib/action_controller/middleware_stack.rb10
-rw-r--r--actionpack/lib/action_controller/middlewares.rb2
-rw-r--r--actionpack/test/controller/middleware_stack_test.rb7
3 files changed, 16 insertions, 3 deletions
diff --git a/actionpack/lib/action_controller/middleware_stack.rb b/actionpack/lib/action_controller/middleware_stack.rb
index ee0ae48ac0..b739a6d72d 100644
--- a/actionpack/lib/action_controller/middleware_stack.rb
+++ b/actionpack/lib/action_controller/middleware_stack.rb
@@ -67,11 +67,17 @@ module ActionController
def build(app)
if block
- klass.new(app, *args, &block)
+ klass.new(app, *build_args, &block)
else
- klass.new(app, *args)
+ klass.new(app, *build_args)
end
end
+
+ private
+
+ def build_args
+ Array(args).map { |arg| arg.respond_to?(:call) ? arg.call : arg }
+ end
end
def initialize(*args, &block)
diff --git a/actionpack/lib/action_controller/middlewares.rb b/actionpack/lib/action_controller/middlewares.rb
index fd70eca1b1..371cf6d8f7 100644
--- a/actionpack/lib/action_controller/middlewares.rb
+++ b/actionpack/lib/action_controller/middlewares.rb
@@ -5,7 +5,7 @@ use "Rack::Lock", :if => lambda {
use "ActionController::Failsafe"
use lambda { ActionController::Base.session_store },
- ActionController::Base.session_options
+ lambda { ActionController::Base.session_options }
use "ActionController::RewindableInput"
use "ActionController::ParamsParser"
diff --git a/actionpack/test/controller/middleware_stack_test.rb b/actionpack/test/controller/middleware_stack_test.rb
index 612a710fa7..918231013a 100644
--- a/actionpack/test/controller/middleware_stack_test.rb
+++ b/actionpack/test/controller/middleware_stack_test.rb
@@ -80,4 +80,11 @@ class MiddlewareStackTest < ActiveSupport::TestCase
end
assert_equal BazMiddleware, @stack.last.klass
end
+
+ test "lazy evaluates middleware arguments" do
+ assert_difference "@stack.size" do
+ @stack.use BazMiddleware, lambda { :foo }
+ end
+ assert_equal [:foo], @stack.last.send(:build_args)
+ end
end