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.
522 523 524 |
# File 'lib/rage/configuration.rb', line 522 def delete(middleware) @objects.reject! { |o, _, _| o == middleware } end |
#include?(middleware) ⇒ Boolean
Check if a middleware is included in the stack.
512 513 514 |
# File 'lib/rage/configuration.rb', line 512 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.
502 503 504 505 506 507 |
# File 'lib/rage/configuration.rb', line 502 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.
482 483 484 485 486 |
# File 'lib/rage/configuration.rb', line 482 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.
462 463 464 465 |
# File 'lib/rage/configuration.rb', line 462 def use(new_middleware, *args, &block) validate!(-1, new_middleware) @objects.insert(-1, [new_middleware, args, block]) end |