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.
237 238 239 |
# File 'lib/rage/configuration.rb', line 237 def initialize @middlewares = [[Rage::FiberWrapper]] end |
Instance Attribute Details
#middlewares ⇒ Object (readonly)
Returns the value of attribute middlewares.
235 236 237 |
# File 'lib/rage/configuration.rb', line 235 def middlewares @middlewares end |
Instance Method Details
#include?(middleware) ⇒ Boolean
258 259 260 |
# File 'lib/rage/configuration.rb', line 258 def include?(middleware) !!find_middleware_index(middleware) rescue false end |
#insert_after(existing_middleware, new_middleware, *args, &block) ⇒ Object
253 254 255 256 |
# File 'lib/rage/configuration.rb', line 253 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
245 246 247 248 249 250 251 |
# File 'lib/rage/configuration.rb', line 245 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
241 242 243 |
# File 'lib/rage/configuration.rb', line 241 def use(new_middleware, *args, &block) insert_after(@middlewares.length - 1, new_middleware, *args, &block) end |