Action Dispatch MiddlewareStack
在指南中了解更多关于 Rails 中间件栈 的信息。
命名空间
- 类 ActionDispatch::MiddlewareStack::InstrumentationProxy
- 类 ActionDispatch::MiddlewareStack::Middleware
方法
- #
- B
- D
- E
- I
- L
- M
- N
- S
- U
包含的模块
属性
[RW] | middlewares |
类公共方法
new(*args) 链接
来源:显示 | 在 GitHub 上
# File actionpack/lib/action_dispatch/middleware/stack.rb, line 76 def initialize(*args) @middlewares = [] yield(self) if block_given? end
实例公共方法
[](i) 链接
来源:显示 | 在 GitHub 上
# File actionpack/lib/action_dispatch/middleware/stack.rb, line 93 def [](i) middlewares[i] end
build(app = nil, &block) 链接
来源:显示 | 在 GitHub 上
# File actionpack/lib/action_dispatch/middleware/stack.rb, line 166 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) 链接
从中间件栈中删除一个中间件。
返回不包含已删除项的中间件数组,如果未找到目标,则返回 nil。
来源:显示 | 在 GitHub 上
# File actionpack/lib/action_dispatch/middleware/stack.rb, line 131 def delete(target) middlewares.reject! { |m| m.name == target.name } end
delete!(target) 链接
从中间件栈中删除一个中间件。
返回不包含已删除项的中间件数组,如果未找到目标,则引发 RuntimeError
。
来源:显示 | 在 GitHub 上
# File actionpack/lib/action_dispatch/middleware/stack.rb, line 139 def delete!(target) delete(target) || (raise "No such middleware to remove: #{target.inspect}") end
each(&block) 链接
来源:显示 | 在 GitHub 上
# File actionpack/lib/action_dispatch/middleware/stack.rb, line 81 def each(&block) @middlewares.each(&block) end
initialize_copy(other) 链接
来源:显示 | 在 GitHub 上
# File actionpack/lib/action_dispatch/middleware/stack.rb, line 102 def initialize_copy(other) self.middlewares = other.middlewares.dup end
insert(index, klass, *args, &block) 链接
也称为:insert_before
来源:显示 | 在 GitHub 上
# File actionpack/lib/action_dispatch/middleware/stack.rb, line 106 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) 链接
来源:显示 | 在 GitHub 上
# File actionpack/lib/action_dispatch/middleware/stack.rb, line 114 def insert_after(index, *args, &block) index = assert_index(index, :after) insert(index + 1, *args, &block) end
last() 链接
来源:显示 | 在 GitHub 上
# File actionpack/lib/action_dispatch/middleware/stack.rb, line 89 def last middlewares.last end
move(target, source) 链接
也称为:move_before
来源:显示 | 在 GitHub 上
# File actionpack/lib/action_dispatch/middleware/stack.rb, line 143 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) 链接
来源:显示 | 在 GitHub 上
# File actionpack/lib/action_dispatch/middleware/stack.rb, line 153 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() 链接
来源:显示 | 在 GitHub 上
# File actionpack/lib/action_dispatch/middleware/stack.rb, line 85 def size middlewares.size end
swap(target, *args, &block) 链接
来源:显示 | 在 GitHub 上
# File actionpack/lib/action_dispatch/middleware/stack.rb, line 120 def swap(target, *args, &block) index = assert_index(target, :before) insert(index, *args, &block) middlewares.delete_at(index + 1) end
unshift(klass, *args, &block) 链接
来源:显示 | 在 GitHub 上
# File actionpack/lib/action_dispatch/middleware/stack.rb, line 97 def unshift(klass, *args, &block) middlewares.unshift(build_middleware(klass, args, block)) end
use(klass, *args, &block) 链接
来源:显示 | 在 GitHub 上
# File actionpack/lib/action_dispatch/middleware/stack.rb, line 161 def use(klass, *args, &block) middlewares.push(build_middleware(klass, args, block)) end