Module: MongoModel::DocumentExtensions::OptimisticLocking::ClassMethods

Defined in:
lib/mongomodel/document/optimistic_locking.rb

Instance Method Summary collapse

Instance Method Details

#lock_optimistically=(value) ⇒ Object


11
12
13
14
15
16
17
18
# File 'lib/mongomodel/document/optimistic_locking.rb', line 11

def lock_optimistically=(value)
  if value == true
    property :_lock_version, Integer, :default => 0, :internal => true, :protected => true
    before_save :increment_lock_version, :if => :locking_enabled?
  else
    properties.delete(:_lock_version)
  end
end

#locking_enabled?Boolean


7
8
9
# File 'lib/mongomodel/document/optimistic_locking.rb', line 7

def locking_enabled?
  properties.include?(:_lock_version)
end