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.
215 216 217 |
# File 'lib/rage/configuration.rb', line 215 def initialize @middlewares = [[Rage::FiberWrapper]] end |
Instance Attribute Details
#middlewares ⇒ Object (readonly)
Returns the value of attribute middlewares.
213 214 215 |
# File 'lib/rage/configuration.rb', line 213 def middlewares @middlewares end |
Instance Method Details
#include?(middleware) ⇒ Boolean
236 237 238 |
# File 'lib/rage/configuration.rb', line 236 def include?(middleware) !!find_middleware_index(middleware) rescue false end |
#insert_after(existing_middleware, new_middleware, *args, &block) ⇒ Object
231 232 233 234 |
# File 'lib/rage/configuration.rb', line 231 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
223 224 225 226 227 228 229 |
# File 'lib/rage/configuration.rb', line 223 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
219 220 221 |
# File 'lib/rage/configuration.rb', line 219 def use(new_middleware, *args, &block) insert_after(@middlewares.length - 1, new_middleware, *args, &block) end |