Class: ActionDispatch::MiddlewareStack
- Inherits:
-
Object
- Object
- ActionDispatch::MiddlewareStack
show all
- Includes:
- Enumerable
- Defined in:
- lib/action_dispatch/middleware/stack.rb
Defined Under Namespace
Classes: InstrumentationProxy, Middleware
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#[](i) ⇒ Object
-
#build(app = nil, &block) ⇒ Object
-
#delete(target) ⇒ Object
-
#each ⇒ Object
-
#initialize(*args) {|_self| ... } ⇒ MiddlewareStack
constructor
A new instance of MiddlewareStack.
-
#initialize_copy(other) ⇒ Object
-
#insert(index, klass, *args, &block) ⇒ Object
(also: #insert_before)
-
#insert_after(index, *args, &block) ⇒ Object
-
#last ⇒ Object
-
#move(target, source) ⇒ Object
(also: #move_before)
-
#move_after(target, source) ⇒ Object
-
#size ⇒ Object
-
#swap(target, *args, &block) ⇒ Object
-
#unshift(klass, *args, &block) ⇒ Object
-
#use(klass, *args, &block) ⇒ Object
Constructor Details
#initialize(*args) {|_self| ... } ⇒ MiddlewareStack
Returns a new instance of MiddlewareStack.
70
71
72
73
|
# File 'lib/action_dispatch/middleware/stack.rb', line 70
def initialize(*args)
@middlewares = []
yield(self) if block_given?
end
|
Instance Attribute Details
#middlewares ⇒ Object
Returns the value of attribute middlewares.
68
69
70
|
# File 'lib/action_dispatch/middleware/stack.rb', line 68
def middlewares
@middlewares
end
|
Instance Method Details
#[](i) ⇒ Object
87
88
89
|
# File 'lib/action_dispatch/middleware/stack.rb', line 87
def [](i)
middlewares[i]
end
|
#build(app = nil, &block) ⇒ Object
148
149
150
151
152
153
154
155
156
157
|
# File 'lib/action_dispatch/middleware/stack.rb', line 148
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) ⇒ Object
121
122
123
|
# File 'lib/action_dispatch/middleware/stack.rb', line 121
def delete(target)
middlewares.delete_if { |m| m.klass == target }
end
|
#each ⇒ Object
75
76
77
|
# File 'lib/action_dispatch/middleware/stack.rb', line 75
def each
@middlewares.each { |x| yield x }
end
|
#initialize_copy(other) ⇒ Object
96
97
98
|
# File 'lib/action_dispatch/middleware/stack.rb', line 96
def initialize_copy(other)
self.middlewares = other.middlewares.dup
end
|
#insert(index, klass, *args, &block) ⇒ Object
Also known as:
insert_before
100
101
102
103
|
# File '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) ⇒ Object
108
109
110
111
|
# File '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
|
#last ⇒ Object
83
84
85
|
# File 'lib/action_dispatch/middleware/stack.rb', line 83
def last
middlewares.last
end
|
#move(target, source) ⇒ Object
Also known as:
move_before
125
126
127
128
129
130
131
|
# File 'lib/action_dispatch/middleware/stack.rb', line 125
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) ⇒ Object
135
136
137
138
139
140
141
|
# File 'lib/action_dispatch/middleware/stack.rb', line 135
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
|
#size ⇒ Object
79
80
81
|
# File 'lib/action_dispatch/middleware/stack.rb', line 79
def size
middlewares.size
end
|
#swap(target, *args, &block) ⇒ Object
114
115
116
117
118
|
# File '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) ⇒ Object
91
92
93
|
# File '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) ⇒ Object
143
144
145
|
# File 'lib/action_dispatch/middleware/stack.rb', line 143
def use(klass, *args, &block)
middlewares.push(build_middleware(klass, args, block))
end
|