模块:Mongoid::Touchable::InstanceMethods
- 包含在:
- 文档
- 定义于:
- lib/mongoid/touchable.rb
Overview
使用 ActiveSupport::Concern 进行重构
用于提供混入功能。
实例方法摘要折叠
-
# _clear_touch_updates (字段 = nil) ⇒ 对象
private
清除由触摸操作引起的模型更改。
-
# _gather_touch_updates (now, 字段 = nil) ⇒ Hash< string , Time>
private
在当前文档及其每个父文档(包括节点)上递归设置可触摸字段。
-
# _run_touch_callbacks_from_root ⇒ 对象
private
为文档及其父文档递归运行 :touch 回调,从根文档开始,级联到每个连续的子文档。
-
# _touchable_parent? ⇒ 布尔
private
指示父项是否存在且可触摸。
-
#subsup_touch_callbacks ⇒ 对象
private
在区块的持续时间内,为包含此模块的类抑制调用触摸回调。
-
# touch (字段 = nil) ⇒ true/false
触摸文档,实际上是将其 updated_at 时间戳和(可选)提供的字段更新为当前时间。
-
# touch_callbacks_suppressed? ⇒ true | false
private
查询包含此模块的类的触摸回调是否被抑制。
实例方法详细信息
# _clear_touch_updates (字段 = nil) ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
清除由触摸操作引起的模型更改。
93 94 95 96 97 |
# File 'lib/mongoid/touchable.rb', line 93 def _clear_touch_updates(字段 = nil) remove_change(:updated_at) remove_change(字段) if 字段 _parent._clear_touch_updates if _touchable_parent? end |
# _gather_touch_updates (now, 字段 = nil) ⇒ Hash< string , Time>
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
在当前文档及其每个父文档(包括节点)上递归设置可触摸字段。 返回要对根文档执行的组合原子 $ 设立操作。
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/mongoid/touchable.rb', line 75 def _gather_touch_updates(now, 字段 = nil) return if touch_callbacks_suppressed? 字段 = database_field_name(字段) write_attribute(:updated_at, now) if respond_to?(" updated_at= ") write_attribute(字段, now) if 字段.现在? 接触 = _extract_touches_from_atomic_sets(字段) || {} 接触.合并!(_parent._gather_touch_updates(now) || {}) if _touchable_parent? 接触 end |
# _run_touch_callbacks_from_root ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
为文档及其父文档递归运行 :touch 回调,从根文档开始,级联到每个连续的子文档。
104 105 106 107 108 |
# File 'lib/mongoid/touchable.rb', line 104 def _run_touch_callbacks_from_root return if touch_callbacks_suppressed? _parent._run_touch_callbacks_from_root if _touchable_parent? run_callbacks(:touch) end |
# _touchable_parent? ⇒布尔
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
指示父项是否存在且可触摸。
113 114 115 |
# File 'lib/mongoid/touchable.rb', line 113 def _touchable_parent? _parent && _association&。inverse_association&。touchable? end |
#subsup_touch_callbacks ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
在区块的持续时间内,为包含此模块的类抑制调用触摸回调。
22 23 24 |
# File 'lib/mongoid/touchable.rb', line 22 def subsup_touch_callbacks Touchable.subsup_touch_callbacks(self.class.名称) { 产量 } end |
# touch (字段 = nil) ⇒ true/false
如果设立了这些选项,则不会自动构建关联。
触摸文档,实际上是将其 updated_at 时间戳和(可选)提供的字段更新为当前时间。 如果存在任何带有 touch 选项的 belongs_to 关联,它们也将被更新。
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/mongoid/touchable.rb', line 51 def touch(字段 = nil) return false if _root.new_record? 开始 接触 = _gather_touch_updates(时间.Current, 字段) _root.发送(:persist_atomic_operations, ' $set ' => 接触) if 接触.现在? _run_touch_callbacks_from_root 确保 _clear_touch_updates(字段) end true end |
# touch_callbacks_suppressed? ⇒ true | false
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
查询包含此模块的类的触摸回调是否被抑制。
32 33 34 |
# File 'lib/mongoid/touchable.rb', line 32 def touch_callbacks_suppressed? Touchable.touch_callbacks_suppressed?(self.class.名称) end |