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 |
# File 'lib/mongoid/locker.rb', line 137 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.
206 207 208 209 210 211 212 213 |
# File 'lib/mongoid/locker.rb', line 206 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.
184 185 186 |
# File 'lib/mongoid/locker.rb', line 184 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.
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/mongoid/locker.rb', line 155 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 |