Module: Mongoid::Locker::ClassMethods

Defined in:
lib/mongoid/locker.rb

Instance Method Summary collapse

Instance Method Details

#lock_timeoutFixnum

Retrieve the lock timeout default for this class.

Returns:

  • (Fixnum)

    the default number of seconds until a lock is considered “expired”, in seconds



35
36
37
38
# File 'lib/mongoid/locker.rb', line 35

def lock_timeout
  # default timeout of five seconds
  @lock_timeout || 5
end

#lockedMongoid::Criteria

A scope to retrieve all locked documents in the collection.

Returns:

  • (Mongoid::Criteria)


13
14
15
# File 'lib/mongoid/locker.rb', line 13

def locked
  where :locked_until.gt => Time.now
end

#timeout_lock_after(new_time) ⇒ void

This method returns an undefined value.

Set the default lock timeout for this class. Note this only applies to new locks. Defaults to five seconds.

Parameters:

  • new_time (Fixnum)

    the default number of seconds until a lock is considered “expired”, in seconds



28
29
30
# File 'lib/mongoid/locker.rb', line 28

def timeout_lock_after(new_time)
  @lock_timeout = new_time
end

#unlockedMongoid::Criteria

A scope to retrieve all unlocked documents in the collection.

Returns:

  • (Mongoid::Criteria)


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

def unlocked
  any_of({ locked_until: nil }, :locked_until.lte => Time.now)
end