aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2015-08-07 12:03:13 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2015-08-07 15:37:31 -0700
commit27eddbb332c4adb533e0699e4b1532c3bd4de222 (patch)
treefc7697591d8d14a3d32f35694f5d96245d3c17ba /actionpack/lib/action_controller
parente4f9a0b92531fa68cc2cdbd52b66904515fcd486 (diff)
downloadrails-27eddbb332c4adb533e0699e4b1532c3bd4de222.tar.gz
rails-27eddbb332c4adb533e0699e4b1532c3bd4de222.tar.bz2
rails-27eddbb332c4adb533e0699e4b1532c3bd4de222.zip
simplify the Middleware constructor
We should do the hard work outside the constructor. Also fix the tests to not directly construct middleware objects, but to go through the stack object.
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r--actionpack/lib/action_controller/metal.rb25
1 files changed, 17 insertions, 8 deletions
diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb
index dc88557e3a..817339dadf 100644
--- a/actionpack/lib/action_controller/metal.rb
+++ b/actionpack/lib/action_controller/metal.rb
@@ -11,18 +11,16 @@ module ActionController
#
class MiddlewareStack < ActionDispatch::MiddlewareStack #:nodoc:
class Middleware < ActionDispatch::MiddlewareStack::Middleware #:nodoc:
- def initialize(klass, *args, &block)
- options = args.extract_options!
- @only = Array(options.delete(:only)).map(&:to_s)
- @except = Array(options.delete(:except)).map(&:to_s)
- args << options unless options.empty?
- super
+ def initialize(klass, args, only, except, block)
+ @only = only
+ @except = except
+ super(klass, args, block)
end
def valid?(action)
- if @only.present?
+ if @only.any?
@only.include?(action)
- elsif @except.present?
+ elsif @except.any?
!@except.include?(action)
else
true
@@ -37,6 +35,17 @@ module ActionController
middleware.valid?(action) ? middleware.build(a) : a
end
end
+
+ private
+
+ def build_middleware(klass, args, block)
+ options = args.extract_options!
+ only = Array(options.delete(:only)).map(&:to_s)
+ except = Array(options.delete(:except)).map(&:to_s)
+ args << options unless options.empty?
+
+ Middleware.new(klass, args, only, except, block)
+ end
end
# <tt>ActionController::Metal</tt> is the simplest possible controller, providing a