class ActionController::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