class Rails::Configuration::MiddlewareStackProxy
MiddlewareStackProxy — это прокси для стека middleware Rails, позволяющий настраивать middleware в приложении. По сути, он работает как регистратор команд, сохраняя каждую команду для выполнения после инициализации поверх стека middleware по умолчанию, поэтому вы можете добавлять, заменять или удалять любые middleware в Rails.
Вы можете добавить собственные middleware с помощью метода config.middleware.use:
config.middleware.use Magical::Unicorns
Это добавит middleware Magical::Unicorns в конец стека. Если вы хотите добавить middleware перед другим, используйте insert_before:
config.middleware.insert_before Rack::Head, Magical::Unicorns
Также есть метод insert_after, который добавит middleware после другого:
config.middleware.insert_after Rack::Head, Magical::Unicorns
Middleware также можно полностью заменить другими:
config.middleware.swap ActionDispatch::Flash, Magical::Unicorns
Middleware можно переместить с одного места на другое:
config.middleware.move_before ActionDispatch::Flash, Magical::Unicorns
Это переместит middleware Magical::Unicorns перед ActionDispatch::Flash. Его также можно переместить после:
config.middleware.move_after ActionDispatch::Flash, Magical::Unicorns
Наконец, middleware можно полностью удалить из стека:
config.middleware.delete ActionDispatch::Flash
Атрибуты
Публичные методы класса
# File railties/lib/rails/configuration.rb, line 47 def initialize(operations = [], delete_operations = []) @operations = operations @delete_operations = delete_operations end
Публичные методы экземпляра
# File railties/lib/rails/configuration.rb, line 70
def delete(...)
@delete_operations << -> middleware { middleware.delete(...) }
end # File railties/lib/rails/configuration.rb, line 58
def insert_after(...)
@operations << -> middleware { middleware.insert_after(...) }
end # File railties/lib/rails/configuration.rb, line 52
def insert_before(...)
@operations << -> middleware { middleware.insert_before(...) }
end # File railties/lib/rails/configuration.rb, line 80
def move_after(...)
@delete_operations << -> middleware { middleware.move_after(...) }
end # File railties/lib/rails/configuration.rb, line 74
def move_before(...)
@delete_operations << -> middleware { middleware.move_before(...) }
end # File railties/lib/rails/configuration.rb, line 62
def swap(...)
@operations << -> middleware { middleware.swap(...) }
end # File railties/lib/rails/configuration.rb, line 84
def unshift(...)
@operations << -> middleware { middleware.unshift(...) }
end # File railties/lib/rails/configuration.rb, line 66
def use(...)
@operations << -> middleware { middleware.use(...) }
end
© 2004–2021 David Heinemeier Hansson
Licensed under the MIT License.