Class: Rage::Configuration::MiddlewareRegistry
- Inherits:
-
Object
- Object
- Rage::Configuration::MiddlewareRegistry
- Defined in:
- lib/rage/configuration.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#delete(middleware) ⇒ Object
Delete a middleware from the stack.
-
#include?(middleware) ⇒ Boolean
Check if a middleware is included in the stack.
-
#insert_after(existing_middleware, new_middleware, *args, &block) ⇒ Object
Insert a new middleware after an existing middleware in the stack.
-
#insert_before(existing_middleware, new_middleware, *args, &block) ⇒ Object
Insert a new middleware before an existing middleware in the stack.
-
#use(new_middleware, *args, &block) ⇒ Object
Add a new middleware to the end of the stack.
Instance Method Details
#delete(middleware) ⇒ Object
Delete a middleware from the stack.
470 471 472 |
# File 'lib/rage/configuration.rb', line 470 def delete(middleware) @objects.reject! { |o, _, _| o == middleware } end |
#include?(middleware) ⇒ Boolean
Check if a middleware is included in the stack.
460 461 462 |
# File 'lib/rage/configuration.rb', line 460 def include?(middleware) @objects.any? { |o, _, _| o == middleware } end |
#insert_after(existing_middleware, new_middleware, *args, &block) ⇒ Object
Insert a new middleware after an existing middleware in the stack.
450 451 452 453 454 455 |
# File 'lib/rage/configuration.rb', line 450 def insert_after(existing_middleware, new_middleware, *args, &block) index = find_object_index(existing_middleware) + 1 index = 0 if @objects.empty? validate!(index, new_middleware) @objects.insert(index, [new_middleware, args, block]) end |
#insert_before(existing_middleware, new_middleware, *args, &block) ⇒ Object
Rage always uses the Rage::FiberWrapper middleware, which wraps every request in a separate fiber. Make sure to always have this middleware in the top of the stack. Placing other middlewares in front may lead to undefined behavior.
Insert a new middleware before an existing middleware in the stack.
430 431 432 433 434 |
# File 'lib/rage/configuration.rb', line 430 def insert_before(existing_middleware, new_middleware, *args, &block) index = find_object_index(existing_middleware) validate!(index, new_middleware) @objects.insert(index, [new_middleware, args, block]) end |
#use(new_middleware, *args, &block) ⇒ Object
This is the recommended way of adding a middleware.
Add a new middleware to the end of the stack.
410 411 412 413 |
# File 'lib/rage/configuration.rb', line 410 def use(new_middleware, *args, &block) validate!(-1, new_middleware) @objects.insert(-1, [new_middleware, args, block]) end |