模块:Mongoid::Persistable::Incrementable
- 扩展方式:
- ActiveSupport::Concern
- 包含在:
- Mongoid::Persistable
- 定义于:
- lib/mongoid/persistable/incrementable.rb
Overview
定义 $inc 操作的行为。
实例方法摘要折叠
-
# inc (increments) ⇒ 文档
将提供的字段按相应的值递增。
实例方法详细信息
# inc (increments) ⇒文档
将提供的字段按相应的值递增。 值可以是正数或负数,如果该字段不存在值,则将其设置为提供的值。
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/mongoid/persistable/incrementable.rb', line 21 def inc(增量) prepare_atomic_operation do |运维| process_atomic_operations(增量) do |字段, 值| 增量 = 值.is_a?(BigDecimal) ? 值.to_f : 值 Current = 属性[字段] new_value = (Current || 0) + 增量 process_attribute 字段, new_value if Executing_atomically? 属性[字段] = new_value 运维[atomic_attribute_name(字段)] = 增量 end { " $inc " => 运维 } 除非 运维.空? end end |