模块:Mongoid::Stateful
- 包含在:
- 可组合
- 定义于:
- lib/mongoid/stateful.rb
Overview
Mongoid::Document 中包含 Mixin 模块,该模块添加了获取文档可以转换的各种生命周期状态的行为。
实例属性摘要折叠
-
#已销毁"> 对象
writeonly
设置已销毁的属性。
-
# flagged_for_destroy ⇒ 对象
writeonly
设置属性 flagged_for_destroy。
-
# previous_new_record ⇒ 对象
writeonly
设置属性 previous_new_record。
实例方法摘要折叠
-
#已销毁? ⇒ true | false
如果
Document
已成功销毁,则返回 true,否则返回 false。 -
# flagged_for_destroy? ⇒ true | false (也称为:#marked_for_destruction?、#_destroy)
返回文档是否已被标记为删除,但尚未销毁。
-
# new_record= (new_value) ⇒ true | false
设置文档是否已保存到数据库中。
-
# new_record? ⇒ true | false
如果文档尚未持久保存到数据库,则返回 true,如果已持久保存到数据库,则返回 false。
-
#持续? ⇒ true | false
检查文档是否已保存到数据库中。
-
# previous_new_record? ⇒ true | false
如果此文档刚刚创建,即在上次保存之前,数据库中不存在该对象,并且 new_record? 会返回 true。
-
# previous_persisted? ⇒ true | false
检查文档之前是否已保存到数据库,但现在已被删除。
-
#可推送? ⇒ true | false
确定是否可以推送文档。
-
# readonly! ⇒ true | false
将文档标记为只读。
-
# readonly? ⇒ true | false
文档是只读的吗?
-
# settable? ⇒ true | false
确定是否可以设立文档。
-
#可更新? ⇒ true | false
文档是否可更新?
实例属性详细信息
#销毁= (值) ⇒对象(只写)
设置已销毁的属性
10 11 12 |
# File 'lib/mongoid/stateful.rb', 第10行 def 销毁=(值) @destroyed = 值 end |
# flagged_for_destroy= (value) ⇒对象(只写)
设置属性 flagged_for_destroy
10 11 12 |
# File 'lib/mongoid/stateful.rb', 第10行 def flagged_for_destroy=(值) @flag_for_destroy = 值 end |
# previous_new_record= (value) ⇒对象(只写)
设置属性 previous_new_record
10 11 12 |
# File 'lib/mongoid/stateful.rb', 第10行 def previous_new_record=(值) @previously_new_record = 值 end |
实例方法详细信息
#已销毁? ⇒ true | false
如果Document
已成功销毁,则返回 true,否则返回 false。 这是由变量 @destroyed 确定的,而不是通过检查数据库来确定的。
87 88 89 |
# File 'lib/mongoid/stateful.rb', 第87行 def 已销毁? @destroyed ||= false end |
# flagged_for_destroy? ⇒ true | false也称为: marked_for_destruction? , _destroy
返回文档是否已被标记为删除,但尚未销毁。 用于子文档的原子拉取。
73 74 75 |
# File 'lib/mongoid/stateful.rb', 第73行 def flagged_for_destroy? @flag_for_destroy ||= false end |
# new_record= (new_value) ⇒ true | false
设置文档是否已保存到数据库中。
17 18 19 20 21 22 23 |
# File 'lib/mongoid/stateful.rb', 第17行 def new_record=(new_value) @new_record ||= false if @new_record && !new_value @previously_new_record = true end @new_record = new_value end |
# new_record? ⇒ true | false
如果文档尚未持久保存到数据库,则返回 true,如果已持久保存到数据库,则返回 false。 这是由变量 @new_record 决定的,如果对象有ID ,则为 NOT 。
33 34 35 |
# File 'lib/mongoid/stateful.rb', 第33行 def new_record? @new_record ||= false end |
#持续? ⇒ true | false
检查文档是否已保存到数据库中。 如果文档已被销毁,则返回 false。
53 54 55 |
# File 'lib/mongoid/stateful.rb', 第53行 def 持续存在? !new_record? && !已销毁? end |
# previous_new_record? ⇒ true | false
如果此文档刚刚创建,即在上次保存之前,数据库中不存在该对象,并且 new_record? 会返回 true。
42 43 44 |
# File 'lib/mongoid/stateful.rb', 第42行 def previous_new_record? @previously_new_record ||= false end |
# previous_persisted? ⇒ true | false
检查文档之前是否已保存到数据库,但现在已被删除。
62 63 64 |
# File 'lib/mongoid/stateful.rb', 第62行 def previous_persisted? !new_record? && 已销毁? end |
#可推送? ⇒ true | false
确定是否可以推送文档。
97 98 99 100 101 102 |
# File 'lib/mongoid/stateful.rb', 第97行 def 可推送? new_record? && && _parent.持续存在? && !_parent.Delayed_atomic_sets[atomic_path] end |
# readonly! ⇒ true | false
将文档标记为只读。 如果尝试保存、更新或销毁文档,将导致引发 ReadonlyDocument 错误。
112 113 114 115 116 117 118 119 |
# File 'lib/mongoid/stateful.rb', 第112行 def readonly! if Mongoid.legacy_readonly Mongoid::警告.warn_legacy_readonly false else @readonly = true end end |
# readonly? ⇒ true | false
文档是只读的吗?
127 128 129 130 131 132 133 |
# File 'lib/mongoid/stateful.rb', 第127行 def 只读? if Mongoid.legacy_readonly __selected_fields != nil else @readonly ||= false end end |
# settable? ⇒ true | false
确定是否可以设立文档。
141 142 143 |
# File 'lib/mongoid/stateful.rb', 第141行 def 可设置? new_record? && && _parent.持续存在? end |
#可更新? ⇒ true | false
文档是否可更新?
151 152 153 |
# File 'lib/mongoid/stateful.rb', 第151行 def 可更新? 持续存在? && 改变? end |