123456789_123456789_123456789_123456789_123456789_

Class: ActionDispatch::MiddlewareStack

Relationships & Source Files
Namespace Children
Classes:
Extension / Inclusion / Inheritance Descendants
Subclasses:
ActionController::MiddlewareStack
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, ::Enumerable
Inherits: Object
Defined in: actionpack/lib/action_dispatch/middleware/stack.rb

Class Method Summary

Instance Attribute Summary

::Enumerable - Included

#many?

Returns true if the enumerable has more than 1 element.

Instance Method Summary

Constructor Details

.new(*args) {|_self| ... } ⇒ MiddlewareStack

Yields:

  • (_self)

Yield Parameters:

  • _self (MiddlewareStack)

    the object that the method was called on

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 57

def initialize(*args)
  @middlewares = []
  yield(self) if block_given?
end

Instance Attribute Details

#middlewares (rw)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 55

attr_accessor :middlewares

Instance Method Details

#[](i)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 74

def [](i)
  middlewares[i]
end

#build(app = nil, &block)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 115

def build(app = nil, &block)
  app ||= block
  raise "MiddlewareStack#build requires an app" unless app
  middlewares.freeze.reverse.inject(app) { |a, e| e.build(a) }
end

#delete(target)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 106

def delete(target)
  middlewares.delete target
end

#each

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 62

def each
  @middlewares.each { |x| yield x }
end

#initialize_copy(other)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 83

def initialize_copy(other)
  self.middlewares = other.middlewares.dup
end

#insert(index, *args, &block) Also known as: #insert_before

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 87

def insert(index, *args, &block)
  index = assert_index(index, :before)
  middleware = self.class::Middleware.new(*args, &block)
  middlewares.insert(index, middleware)
end

#insert_after(index, *args, &block)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 95

def insert_after(index, *args, &block)
  index = assert_index(index, :after)
  insert(index + 1, *args, &block)
end

#insert_before(index, *args, &block)

Alias for #insert.

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 93

alias_method :insert_before, :insert

#last

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 70

def last
  middlewares.last
end

#size

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 66

def size
  middlewares.size
end

#swap(target, *args, &block)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 100

def swap(target, *args, &block)
  index = assert_index(target, :before)
  insert(index, *args, &block)
  middlewares.delete_at(index + 1)
end

#unshift(*args, &block)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 78

def unshift(*args, &block)
  middleware = self.class::Middleware.new(*args, &block)
  middlewares.unshift(middleware)
end

#use(*args, &block)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 110

def use(*args, &block)
  middleware = self.class::Middleware.new(*args, &block)
  middlewares.push(middleware)
end