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

::Enumerable - Included

#exclude?

The negative of the Enumerable#include?.

#index_by

Convert an enumerable to a hash.

#pluck

Convert an enumerable to an array based on the given key.

#sum

Calculates a sum from the elements.

#without

Returns a copy of the enumerable without the specified elements.

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 45

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 43

attr_accessor :middlewares

Instance Method Details

#[](i)

[ GitHub ]

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

def [](i)
  middlewares[i]
end

#build(app = nil, &block)

[ GitHub ]

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

def build(app = nil, &block)
  middlewares.freeze.reverse.inject(app || block) { |a, e| e.build(a) }
end

#delete(target)

[ GitHub ]

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

def delete(target)
  middlewares.delete_if { |m| m.klass == target }
end

#each

[ GitHub ]

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

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

#initialize_copy(other)

[ GitHub ]

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

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

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

[ GitHub ]

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

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)

[ GitHub ]

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

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.

[ GitHub ]

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

alias_method :insert_before, :insert

#last

[ GitHub ]

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

def last
  middlewares.last
end

#size

[ GitHub ]

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

def size
  middlewares.size
end

#swap(target, *args, &block)

[ GitHub ]

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

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

#unshift(klass, *args, &block)

[ GitHub ]

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

def unshift(klass, *args, &block)
  middlewares.unshift(build_middleware(klass, args, block))
end

#use(klass, *args, &block)

[ GitHub ]

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

def use(klass, *args, &block)
  middlewares.push(build_middleware(klass, args, block))
end