Module: Mongoid::Locking

Defined in:
lib/mongoid/locking.rb,
lib/mongoid/locking/retry.rb,
lib/mongoid/locking/version.rb,
lib/mongoid/locking/reloadable.rb,
lib/mongoid/locking/selectable.rb,
lib/mongoid/locking/persistable.rb,
lib/mongoid/locking/contextual/mongo.rb,
lib/mongoid/locking/contextual/atomic.rb,
lib/mongoid/locking/persistable/creatable.rb,
lib/mongoid/locking/persistable/updatable.rb,
lib/mongoid/locking/association/embedded/batchable.rb

Overview

Adds optimistic locking to a Mongoid::Document class.

Since:

  • 0.1.0

Defined Under Namespace

Modules: Association, Contextual, Persistable, Reloadable, Retry, Selectable

Constant Summary collapse

VERSION =

Since:

  • 0.1.0

"1.3.0"

Class Method Summary collapse

Class Method Details

.backoff_algorithm(retries) ⇒ Object

Since:

  • 0.1.0



30
31
32
# File 'lib/mongoid/locking.rb', line 30

def backoff_algorithm(retries)
  (2**retries) + rand
end

.included(base) ⇒ Object

Since:

  • 0.1.0



21
22
23
24
25
26
27
28
# File 'lib/mongoid/locking.rb', line 21

def included(base)
  base.field :lock_version, type: Integer
  base.before_create { self.lock_version = 0 }

  base.include Mongoid::Locking::Selectable
  base.include Mongoid::Locking::Reloadable
  base.include Mongoid::Locking::Retry
end