class ActionController::MiddlewareStack
:nodoc:
end
use AuthenticationMiddleware, except: [:index, :show]
class PostsController < ApplicationController
allowing the following syntax in controllers:
Extend ActionDispatch middleware stack to make it aware of options
= Action Controller MiddlewareStack
def build(action, app = nil, &block)
def build(action, app = nil, &block) action = action.to_s middlewares.reverse.inject(app || block) do |a, middleware| middleware.valid?(action) ? middleware.build(a) : a end end
def build_middleware(klass, args, block)
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? strategy = NULL list = nil if only.any? strategy = INCLUDE list = only elsif except.any? strategy = EXCLUDE list = except end Middleware.new(klass, args, list, strategy, block) end