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.
137 138 139 140 141 142 143 144 145 |
# File 'lib/mongoid/locker.rb', line 137 def locked where( '$and': [ { locking_name_field => { '$exists': true, '$ne': nil } }, { locked_at_field => { '$exists': true, '$ne': nil } }, { '$where': "new Date() - this.#{locked_at_field} < #{lock_timeout * 1000}" } ] ) end |
#locker(**params) ⇒ Object
Sets configuration for this class.
209 210 211 212 213 214 215 216 |
# File 'lib/mongoid/locker.rb', line 209 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.
187 188 189 |
# File 'lib/mongoid/locker.rb', line 187 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.
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/mongoid/locker.rb', line 156 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 } } ] }, { '$where': "new Date() - this.#{locked_at_field} >= #{lock_timeout * 1000}" } ] ) end |