Module: Mongoid::Locker::ClassMethods
- Defined in:
- lib/mongoid/locker.rb
Instance Method Summary collapse
-
#locked ⇒ Mongoid::Criteria
A scope to retrieve all locked documents in the collection.
-
#locker(**params) ⇒ Object
Sets configuration for this class.
-
#unlock_all ⇒ Integer
Unlock all locked documents in the collection.
-
#unlocked ⇒ Mongoid::Criteria
A scope to retrieve all unlocked documents in the collection.
Instance Method Details
#locked ⇒ Mongoid::Criteria
A scope to retrieve all locked documents in the collection.
134 135 136 137 138 139 140 141 |
# File 'lib/mongoid/locker.rb', line 134 def locked where( '$and': [ { locking_name_field => { '$exists': true, '$ne': nil } }, { locked_at_field => { '$gte': Time.now.utc - (lock_timeout * 1000) } } ] ) end |
#locker(**params) ⇒ Object
Sets configuration for this class.
203 204 205 206 207 208 209 210 |
# File 'lib/mongoid/locker.rb', line 203 def locker(**params) invalid_parameters = params.keys - Mongoid::Locker.singleton_class.const_get('MODULE_METHODS') raise Mongoid::Locker::Errors::InvalidParameter.new(self.class, invalid_parameters.first) unless invalid_parameters.empty? params.each_pair do |key, value| send("#{key}=", value) end end |
#unlock_all ⇒ Integer
Unlock all locked documents in the collection. Sets locking_name_field and locked_at_field fields to nil. Returns number of unlocked documents.
181 182 183 |
# File 'lib/mongoid/locker.rb', line 181 def unlock_all update_all('$set': { locking_name_field => nil, locked_at_field => nil }).modified_count end |
#unlocked ⇒ Mongoid::Criteria
A scope to retrieve all unlocked documents in the collection.
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/mongoid/locker.rb', line 152 def unlocked where( '$or': [ { '$or': [ { locking_name_field => { '$exists': false } }, { locked_at_field => { '$exists': false } } ] }, { '$or': [ { locking_name_field => { '$eq': nil } }, { locked_at_field => { '$eq': nil } } ] }, { locked_at_field => { '$lt': Time.now.utc - (lock_timeout * 1000) } } ] ) end |