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