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


39
40
41
42
# File 'lib/mongoid/locker.rb', line 39

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)

17
18
19
# File 'lib/mongoid/locker.rb', line 17

def locked
  where locked_until_field.gt => Time.now.utc
end

#locked_at_fieldObject

Returns field name used to set locked at time for this class.


51
52
53
# File 'lib/mongoid/locker.rb', line 51

def locked_at_field
  class_variable_get(:@@locked_at_field)
end

#locked_until_fieldObject

Returns field name used to set locked until time for this class.


56
57
58
# File 'lib/mongoid/locker.rb', line 56

def locked_until_field
  class_variable_get(:@@locked_until_field)
end

#locker(locked_at_field: nil, locked_until_field: nil) ⇒ Object

Set locked_at_field and locked_until_field names for this class


45
46
47
48
# File 'lib/mongoid/locker.rb', line 45

def locker(locked_at_field: nil, locked_until_field: nil)
  class_variable_set(:@@locked_at_field, locked_at_field) if locked_at_field
  class_variable_set(:@@locked_until_field, locked_until_field) if locked_until_field
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


32
33
34
# File 'lib/mongoid/locker.rb', line 32

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)

24
25
26
# File 'lib/mongoid/locker.rb', line 24

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