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.
443 444 445 |
# File 'lib/rage/configuration.rb', line 443 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.
435 436 437 438 |
# File 'lib/rage/configuration.rb', line 435 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.
413 414 415 416 417 418 419 |
# File 'lib/rage/configuration.rb', line 413 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.
394 395 396 |
# File 'lib/rage/configuration.rb', line 394 def use(new_middleware, *args, &block) insert_after(@middlewares.length - 1, new_middleware, *args, &block) end |