Class: Rage::Configuration::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/rage/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMiddleware

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

#middlewaresObject (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

Returns:

  • (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