Class: Rage::Configuration::Middleware
- Inherits:
-
Object
- Object
- Rage::Configuration::Middleware
- Defined in:
- lib/rage/configuration.rb
Instance Method Summary collapse
-
#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
#include?(middleware) ⇒ Boolean
Check if a middleware is included in the stack.
451 452 453 |
# File 'lib/rage/configuration.rb', line 451 def include?(middleware) !!find_middleware_index(middleware) rescue false end |
#insert_after(existing_middleware, new_middleware, *args, &block) ⇒ Object
Insert a new middleware after an existing middleware in the stack.
443 444 445 446 |
# File 'lib/rage/configuration.rb', line 443 def insert_after(existing_middleware, new_middleware, *args, &block) index = find_middleware_index(existing_middleware) @middlewares = (@middlewares[0..index] + [[new_middleware, args, block]] + @middlewares[index + 1..]).uniq(&:first) end |
#insert_before(existing_middleware, new_middleware, *args, &block) ⇒ Object
Note:
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.
421 422 423 424 425 426 427 |
# File 'lib/rage/configuration.rb', line 421 def insert_before(existing_middleware, new_middleware, *args, &block) index = find_middleware_index(existing_middleware) if index == 0 && @middlewares[0][0] == Rage::FiberWrapper puts("Warning: inserting #{new_middleware} before Rage::FiberWrapper may lead to undefined behavior.") end @middlewares = (@middlewares[0...index] + [[new_middleware, args, block]] + @middlewares[index..]).uniq(&:first) end |
#use(new_middleware, *args, &block) ⇒ Object
Note:
This is the recommended way of adding a middleware.
Add a new middleware to the end of the stack.
402 403 404 |
# File 'lib/rage/configuration.rb', line 402 def use(new_middleware, *args, &block) insert_after(@middlewares.length - 1, new_middleware, *args, &block) end |