Module: Mongoid::Locker::Wrapper

Defined in:
lib/mongoid/locker/wrapper2.rb,
lib/mongoid/locker/wrapper3.rb,
lib/mongoid/locker/wrapper4.rb,
lib/mongoid/locker/wrapper5.rb,
lib/mongoid/locker/wrapper6.rb

Overview

Normalizes queries between various Mongoid versions.

Class Method Summary collapse

Class Method Details

.locked_until(doc) ⇒ Time

Determine whether the provided document is locked in the database or not.

Parameters:

  • The (Class)

    model instance

Returns:

  • (Time)

    The timestamp of when the document is locked until, nil if not locked.



19
20
21
22
23
# File 'lib/mongoid/locker/wrapper2.rb', line 19

def self.locked_until(doc)
  existing_query = { _id: doc.id, locked_until: { '$exists' => true } }
  existing = doc.class.collection.find_one(existing_query, fields: { locked_until: 1 })
  existing ? existing['locked_until'] : nil
end

.update(klass, query, setter) ⇒ Boolean

Update the document for the provided Class matching the provided query with the provided setter.

Parameters:

  • The (Class)

    model class

  • The (Hash)

    Mongoid query

  • The (Hash)

    Mongoid setter

Returns:

  • (Boolean)

    true if the document was successfully updated, false otherwise



11
12
13
# File 'lib/mongoid/locker/wrapper2.rb', line 11

def self.update(klass, query, setter)
  klass.collection.update(query, setter, safe: true)['n'] == 1
end