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.



200
201
202
# File 'lib/rage/configuration.rb', line 200

def initialize
  @middlewares = [[Rage::FiberWrapper]]
end

Instance Attribute Details

#middlewaresObject (readonly)

Returns the value of attribute middlewares.



198
199
200
# File 'lib/rage/configuration.rb', line 198

def middlewares
  @middlewares
end

Instance Method Details

#insert_after(existing_middleware, new_middleware, *args, &block) ⇒ Object



216
217
218
219
# File 'lib/rage/configuration.rb', line 216

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



208
209
210
211
212
213
214
# File 'lib/rage/configuration.rb', line 208

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



204
205
206
# File 'lib/rage/configuration.rb', line 204

def use(new_middleware, *args, &block)
  insert_after(@middlewares.length - 1, new_middleware, *args, &block)
end