class ActionDispatch::MiddlewareStack
in the guides.
stack}[guides.rubyonrails.org/rails_on_rack.html#action-dispatcher-middleware-stack]
Read more about {Rails middleware
= Action Dispatch MiddlewareStack
def [](i)
def [](i) middlewares[i] end
def assert_index(index, where)
def assert_index(index, where) i = index.is_a?(Integer) ? index : index_of(index) raise "No such middleware to insert #{where}: #{index.inspect}" unless i i end
def build(app = nil, &block)
def build(app = nil, &block) instrumenting = ActiveSupport::Notifications.notifier.listening?(InstrumentationProxy::EVENT_NAME) middlewares.freeze.reverse.inject(app || block) do |a, e| if instrumenting e.build_instrumented(a) else e.build(a) end end end
def build_middleware(klass, args, block)
def build_middleware(klass, args, block) Middleware.new(klass, args, block) end
def delete(target)
Returns the array of middlewares not including the deleted item, or
Deletes a middleware from the middleware stack.
def delete(target) middlewares.reject! { |m| m.name == target.name } end
def delete!(target)
Returns the array of middlewares not including the deleted item, or
Deletes a middleware from the middleware stack.
def delete!(target) delete(target) || (raise "No such middleware to remove: #{target.inspect}") end
def each(&block)
def each(&block) @middlewares.each(&block) end
def index_of(klass)
def index_of(klass) middlewares.index do |m| m.name == klass.name end end
def initialize(*args)
def initialize(*args) @middlewares = [] yield(self) if block_given? end
def initialize_copy(other)
def initialize_copy(other) self.middlewares = other.middlewares.dup end
def insert(index, klass, *args, &block)
def insert(index, klass, *args, &block) index = assert_index(index, :before) middlewares.insert(index, build_middleware(klass, args, block)) end
def insert_after(index, *args, &block)
def insert_after(index, *args, &block) index = assert_index(index, :after) insert(index + 1, *args, &block) end
def last
def last middlewares.last end
def move(target, source)
def move(target, source) source_index = assert_index(source, :before) source_middleware = middlewares.delete_at(source_index) target_index = assert_index(target, :before) middlewares.insert(target_index, source_middleware) end
def move_after(target, source)
def move_after(target, source) source_index = assert_index(source, :after) source_middleware = middlewares.delete_at(source_index) target_index = assert_index(target, :after) middlewares.insert(target_index + 1, source_middleware) end
def size
def size middlewares.size end
def swap(target, *args, &block)
def swap(target, *args, &block) index = assert_index(target, :before) insert(index, *args, &block) middlewares.delete_at(index + 1) end
def unshift(klass, *args, &block)
def unshift(klass, *args, &block) middlewares.unshift(build_middleware(klass, args, block)) end
def use(klass, *args, &block)
def use(klass, *args, &block) middlewares.push(build_middleware(klass, args, block)) end