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.
609 610 611 |
# File 'lib/rage/configuration.rb', line 609 def delete(middleware) @objects.reject! { |o, _, _| o == middleware } end |
#include?(middleware) ⇒ Boolean
Check if a middleware is included in the stack.
599 600 601 |
# File 'lib/rage/configuration.rb', line 599 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.
589 590 591 592 593 594 |
# File 'lib/rage/configuration.rb', line 589 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.
569 570 571 572 573 |
# File 'lib/rage/configuration.rb', line 569 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.
549 550 551 552 |
# File 'lib/rage/configuration.rb', line 549 def use(new_middleware, *args, &block) validate!(-1, new_middleware) @objects.insert(-1, [new_middleware, args, block]) end |