Class: ActionDispatch::MiddlewareStack
Defined Under Namespace
Classes: Middleware
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Enumerable
#as_json, #each_with_object, #exclude?, #group_by, #index_by, #many?, #sum
Constructor Details
#initialize(*args) {|_self| ... } ⇒ MiddlewareStack
Returns a new instance of MiddlewareStack.
57
58
59
60
|
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 57
def initialize(*args)
@middlewares = []
yield(self) if block_given?
end
|
Instance Attribute Details
#middlewares ⇒ Object
Returns the value of attribute middlewares
55
56
57
|
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 55
def middlewares
@middlewares
end
|
Instance Method Details
74
75
76
|
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 74
def [](i)
middlewares[i]
end
|
#build(app = nil, &block) ⇒ Object
109
110
111
112
113
|
# File 'actionpack/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 'actionpack/lib/action_dispatch/middleware/stack.rb', line 100
def delete(target)
middlewares.delete target
end
|
62
63
64
|
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 62
def each
@middlewares.each { |x| yield x }
end
|
#initialize_copy(other) ⇒ Object
78
79
80
|
# File 'actionpack/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 'actionpack/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 'actionpack/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
|
70
71
72
|
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 70
def last
middlewares.last
end
|
66
67
68
|
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 66
def size
middlewares.size
end
|
#swap(target, *args, &block) ⇒ Object
95
96
97
98
|
# File 'actionpack/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 'actionpack/lib/action_dispatch/middleware/stack.rb', line 104
def use(*args, &block)
middleware = self.class::Middleware.new(*args, &block)
middlewares.push(middleware)
end
|