Class: ActionDispatch::MiddlewareStack
- Inherits:
-
Object
- Object
- ActionDispatch::MiddlewareStack
show all
- Includes:
- Enumerable
- Defined in:
- lib/action_dispatch/middleware/stack.rb
Defined Under Namespace
Classes: 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
-
#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.
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
#middlewares ⇒ Object
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
|
#each ⇒ Object
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
|
#last ⇒ Object
58
59
60
|
# File 'lib/action_dispatch/middleware/stack.rb', line 58
def last
middlewares.last
end
|
#size ⇒ Object
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
|