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.
600 601 602 |
# File 'lib/rage/configuration.rb', line 600 def delete(middleware) @objects.reject! { |o, _, _| o == middleware } end |
#include?(middleware) ⇒ Boolean
Check if a middleware is included in the stack.
590 591 592 |
# File 'lib/rage/configuration.rb', line 590 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.
580 581 582 583 584 585 |
# File 'lib/rage/configuration.rb', line 580 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.
560 561 562 563 564 |
# File 'lib/rage/configuration.rb', line 560 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.
540 541 542 543 |
# File 'lib/rage/configuration.rb', line 540 def use(new_middleware, *args, &block) validate!(-1, new_middleware) @objects.insert(-1, [new_middleware, args, block]) end |