模块:Mongoid::Document::ClassMethods
- 定义于:
- lib/mongoid/ 文档.rb
Overview
Document 对象的类级方法。
实例方法摘要折叠
-
# _mongoid_clear_types ⇒ 对象
private
清除 @_type缓存。
-
# _types ⇒ Array<Class>
返回使用此类作为基类时要查询的所有类型。
-
#construct_document (attrs = nil, options = {}) ⇒ 文档
private
分配并构造文档。
-
# i 18 n_scope ⇒ 符号
将18范围设置为 以覆盖 ActiveModel。
-
#instantiate (attrs = nil, selected_fields = nil, &block) ⇒ 文档
仅当从数据库加载或属性已进行类型转换时,才实例化新对象。
-
#instantiate_document (attrs = nil, Selected_fields = nil, options = {}) {|Mongoid::Document| ... } ⇒ 文档
private
实例化文档。
-
# logger ⇒ 记录器
返回记录器。
-
# with_callbacks (execute_callbacks) ⇒ 对象
指示区块中是否应默认调用回调。
实例方法详细信息
# _mongoid_clear_types ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
清除 @_type缓存。 这通常在更改类上的鉴别器键/值时调用。
463 464 465 466 |
# File 'lib/mongoid/ 文档.rb', 第463行 def _mongoid_clear_types @_types = nil 超类._mongoid_clear_types if 会遗传吗? end |
# _types ⇒ Array<Class>
返回使用此类作为基类时要查询的所有类型。
452 453 454 |
# File 'lib/mongoid/ 文档.rb', 第452行 def _types @_types ||= (descendants + [ self ]).uniq.map(和:discriminator_value) end |
#construct_document (attrs = nil, options = {}) ⇒文档
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
注意:
Ruby 2 .x 错误导致选项哈希无法成为关键字参数。 一旦放弃支持Ruby 2 .x 的支持,我们就可以将选项哈希重新实现为关键字参数。 请参阅bugs.Ruby-lang.org/issues/ 15753
分配并构造文档。
441 442 443 444 |
# File 'lib/mongoid/ 文档.rb', 第441行 def construct_document(attrs = nil, = {}) execute_callbacks = .获取(:execute_callbacks, 线程化.execute_callbacks?) with_callbacks(execute_callbacks) { new(attrs) } end |
# i 18 n_scope ⇒符号
将18范围设置为 以覆盖 ActiveModel。
471 472 473 |
# File 'lib/mongoid/ 文档.rb', 第471行 def i 18 n_scope :mongoid end |
#instantiate (attrs = nil, selected_fields = nil, &block) ⇒文档
仅当从数据库加载或属性已进行类型转换时,才实例化新对象。
386 387 388 |
# File 'lib/mongoid/ 文档.rb', 第386行 def 实例化(attrs = nil, created_fields = nil, 和块) instantiate_document(attrs, created_fields, 和块) end |
#instantiate_document (attrs = nil, Selected_fields = nil, options = {}) {|Mongoid::Document| ... } ⇒文档
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
注意:
Ruby 2 .x 错误导致选项哈希无法成为关键字参数。 一旦放弃支持Ruby 2 .x 的支持,我们就可以将选项哈希重新实现为关键字参数。
实例化文档。
410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
# File 'lib/mongoid/ 文档.rb', 第410行 def instantiate_document(attrs = nil, created_fields = nil, = {}, 和块) execute_callbacks = .获取(:execute_callbacks, 线程化.execute_callbacks?) 属性 = attrs&。to_h || {} doc = 分配 doc.__selected_fields = created_fields doc.instance_variable_set(:@attributes, 属性) doc.instance_variable_set(:@attributes_before_type_cast, 属性.dup) doc._handle_callbacks_after_instantiation(execute_callbacks, 和块) doc. doc end |
# with_callbacks (execute_callbacks) ⇒对象
指示区块中是否应默认调用回调。 在可用的情况下,始终可以通过传递 'execute_callbacks: true' 来显式调用回调。
367 368 369 370 371 372 373 |
# File 'lib/mongoid/ 文档.rb', 第367行 def with_callbacks(execute_callbacks) 已保存, 线程化.execute_callbacks = 线程化.execute_callbacks?, execute_callbacks 产量 确保 线程化.execute_callbacks = 已保存 end |