Class: ActionDispatch::MiddlewareStack

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/action_dispatch/middleware/stack.rb

Direct Known Subclasses

ActionController::MiddlewareStack

Defined Under Namespace

Classes: Middleware

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) {|_self| ... } ⇒ MiddlewareStack

Returns a new instance of MiddlewareStack.

Yields:

  • (_self)

Yield Parameters:



45
46
47
48
# File 'lib/action_dispatch/middleware/stack.rb', line 45

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

Instance Attribute Details

#middlewaresObject

Returns the value of attribute middlewares.



43
44
45
# File 'lib/action_dispatch/middleware/stack.rb', line 43

def middlewares
  @middlewares
end

Instance Method Details

#[](i) ⇒ Object



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

def [](i)
  middlewares[i]
end

#build(app = nil, &block) ⇒ Object



100
101
102
# File '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) ⇒ Object



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

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

#eachObject



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

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

#initialize_copy(other) ⇒ Object



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

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

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



74
75
76
77
# File '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) ⇒ Object



81
82
83
84
# File '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

#lastObject



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

def last
  middlewares.last
end

#sizeObject



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

def size
  middlewares.size
end

#swap(target, *args, &block) ⇒ Object



86
87
88
89
90
# File '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) ⇒ Object



66
67
68
# File '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) ⇒ Object



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

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