Class: Rage::Configuration::Middleware
- Inherits:
-
Object
- Object
- Rage::Configuration::Middleware
- Defined in:
- lib/rage/configuration.rb
Instance Attribute Summary collapse
-
#middlewares ⇒ Object
readonly
Returns the value of attribute middlewares.
Instance Method Summary collapse
- #include?(middleware) ⇒ Boolean
-
#initialize ⇒ Middleware
constructor
A new instance of Middleware.
- #insert_after(existing_middleware, new_middleware, *args, &block) ⇒ Object
- #insert_before(existing_middleware, new_middleware, *args, &block) ⇒ Object
- #use(new_middleware, *args, &block) ⇒ Object
Constructor Details
#initialize ⇒ Middleware
Returns a new instance of Middleware.
273 274 275 |
# File 'lib/rage/configuration.rb', line 273 def initialize @middlewares = [[Rage::FiberWrapper]] end |
Instance Attribute Details
#middlewares ⇒ Object (readonly)
Returns the value of attribute middlewares.
271 272 273 |
# File 'lib/rage/configuration.rb', line 271 def middlewares @middlewares end |
Instance Method Details
#include?(middleware) ⇒ Boolean
294 295 296 |
# File 'lib/rage/configuration.rb', line 294 def include?(middleware) !!find_middleware_index(middleware) rescue false end |
#insert_after(existing_middleware, new_middleware, *args, &block) ⇒ Object
289 290 291 292 |
# File 'lib/rage/configuration.rb', line 289 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
281 282 283 284 285 286 287 |
# File 'lib/rage/configuration.rb', line 281 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
277 278 279 |
# File 'lib/rage/configuration.rb', line 277 def use(new_middleware, *args, &block) insert_after(@middlewares.length - 1, new_middleware, *args, &block) end |