Module: Mongoid::Persistable::Maxable
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
ActiveSupport::Concern
|
|
Defined in: | lib/mongoid/persistable/maxable.rb |
Overview
Defines behavior for setting a field (or fields) to the larger of either it’s current value, or a given value.
Instance Method Summary
-
#clamp_lower_bound(fields)
Alias for #set_max.
-
#set_max(fields) ⇒ Document
(also: #clamp_lower_bound)
::Set
the given field or fields to the larger of either it’s current value, or a given value.
Instance Method Details
#clamp_lower_bound(fields)
Alias for #set_max.
# File 'lib/mongoid/persistable/maxable.rb', line 34
alias :clamp_lower_bound :set_max
#set_max(fields) ⇒ Document Also known as: #clamp_lower_bound
::Set
the given field or fields to the larger of either it’s current value, or a given value.
# File 'lib/mongoid/persistable/maxable.rb', line 22
def set_max(fields) prepare_atomic_operation do |ops| process_atomic_operations(fields) do |field, value| current_value = attributes[field] if value > current_value process_attribute field, value ops[atomic_attribute_name(field)] = value end end { "$max" => ops } unless ops.empty? end end