Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Lazy evaluate middleware arguments [#2028 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information...
commit 53fe301a42f9d18b4a8a475e9babf64c621369ae 1 parent 9702636
@svenfuchs svenfuchs authored josh committed
View
10 actionpack/lib/action_controller/middleware_stack.rb
@@ -67,11 +67,17 @@ def inspect
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)
View
2  actionpack/lib/action_controller/middlewares.rb
@@ -5,7 +5,7 @@
use "ActionController::Failsafe"
use lambda { ActionController::Base.session_store },
- ActionController::Base.session_options
+ lambda { ActionController::Base.session_options }
use "ActionController::RewindableInput"
use "ActionController::ParamsParser"
View
7 actionpack/test/controller/middleware_stack_test.rb
@@ -80,4 +80,11 @@ def setup
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
Please sign in to comment.
Something went wrong with that request. Please try again.