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:



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

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

Instance Attribute Details

#middlewaresObject

Returns the value of attribute middlewares.



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

def middlewares
  @middlewares
end

Instance Method Details

#[](i) ⇒ Object



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

def [](i)
  middlewares[i]
end

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



109
110
111
112
113
# File 'lib/action_dispatch/middleware/stack.rb', line 109

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

#delete(target) ⇒ Object



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

def delete(target)
  middlewares.delete target
end

#eachObject



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

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

#initialize_copy(other) ⇒ Object



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

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

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



82
83
84
85
86
# File 'lib/action_dispatch/middleware/stack.rb', line 82

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) ⇒ Object



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

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

#lastObject



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

def last
  middlewares.last
end

#sizeObject



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

def size
  middlewares.size
end

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



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

def swap(target, *args, &block)
  insert_before(target, *args, &block)
  delete(target)
end

#use(*args, &block) ⇒ Object



104
105
106
107
# File 'lib/action_dispatch/middleware/stack.rb', line 104

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