Namespace

Class

Methods

Included Modules

Attributes

[RW] middlewares

Class Public methods

new(*args)

# File actionpack/lib/action_dispatch/middleware/stack.rb, line 70
def initialize(*args)
  @middlewares = []
  yield(self) if block_given?
end

Instance Public methods

[](i)

# File actionpack/lib/action_dispatch/middleware/stack.rb, line 87
def [](i)
  middlewares[i]
end

build(app = nil, &block)

# File actionpack/lib/action_dispatch/middleware/stack.rb, line 160
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

delete(target)

Deletes a middleware from the middleware stack.

Returns the array of middlewares not including the deleted item, or returns nil if the target is not found.

# File actionpack/lib/action_dispatch/middleware/stack.rb, line 125
def delete(target)
  middlewares.reject! { |m| m.name == target.name }
end

delete!(target)

Deletes a middleware from the middleware stack.

Returns the array of middlewares not including the deleted item, or raises RuntimeError if the target is not found.

# File actionpack/lib/action_dispatch/middleware/stack.rb, line 133
def delete!(target)
  delete(target) || (raise "No such middleware to remove: #{target.inspect}")
end

each(&block)

# File actionpack/lib/action_dispatch/middleware/stack.rb, line 75
def each(&block)
  @middlewares.each(&block)
end

initialize_copy(other)

# File actionpack/lib/action_dispatch/middleware/stack.rb, line 96
def initialize_copy(other)
  self.middlewares = other.middlewares.dup
end

insert(index, klass, *args, &block)

Also aliased as: insert_before
# File actionpack/lib/action_dispatch/middleware/stack.rb, line 100
def insert(index, klass, *args, &block)
  index = assert_index(index, :before)
  middlewares.insert(index, build_middleware(klass, args, block))
end

insert_after(index, *args, &block)

# File actionpack/lib/action_dispatch/middleware/stack.rb, line 108
def insert_after(index, *args, &block)
  index = assert_index(index, :after)
  insert(index + 1, *args, &block)
end

insert_before(index, klass, *args, &block)

Alias for: insert

last()

# File actionpack/lib/action_dispatch/middleware/stack.rb, line 83
def last
  middlewares.last
end

move(target, source)

Also aliased as: move_before
# File actionpack/lib/action_dispatch/middleware/stack.rb, line 137
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

move_after(target, source)

# File actionpack/lib/action_dispatch/middleware/stack.rb, line 147
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

move_before(target, source)

Alias for: move

size()

# File actionpack/lib/action_dispatch/middleware/stack.rb, line 79
def size
  middlewares.size
end

swap(target, *args, &block)

# File actionpack/lib/action_dispatch/middleware/stack.rb, line 114
def swap(target, *args, &block)
  index = assert_index(target, :before)
  insert(index, *args, &block)
  middlewares.delete_at(index + 1)
end

unshift(klass, *args, &block)

# File actionpack/lib/action_dispatch/middleware/stack.rb, line 91
def unshift(klass, *args, &block)
  middlewares.unshift(build_middleware(klass, args, block))
end

use(klass, *args, &block)

# File actionpack/lib/action_dispatch/middleware/stack.rb, line 155
def use(klass, *args, &block)
  middlewares.push(build_middleware(klass, args, block))
end