模块:Mongoid::Persistable::Multipliable
Overview
定义 $mul 操作的行为。
实例方法摘要折叠
-
# mul (factors) ⇒ 文档
将提供的字段乘以相应的值。
实例方法详细信息
# mul (factors) ⇒文档
将提供的字段乘以相应的值。 值可以是正数或负数,如果该字段不存在值,则该值将设立为零。
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/mongoid/persistable/multipliable.rb', line 21 def mul(因素) 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 { "$mul" => 运维 } 除非 运维.空? end end |