class Mongo::Lock::Drivers::Base

Attributes

lock[RW]

Public Class Methods

new(lock) click to toggle source
# File lib/mongo-lock/drivers/base.rb, line 8
def initialize lock
  self.lock = lock
end

Public Instance Methods

find_and_update(time, options) click to toggle source
# File lib/mongo-lock/drivers/base.rb, line 29
def find_and_update time, options
  options[:expire_at] = lock.expires_at + time
  find_and_modify options
end
find_or_insert(options) click to toggle source
# File lib/mongo-lock/drivers/base.rb, line 23
def find_or_insert options
  options[:expire_at] = Time.now + options[:expire_in]
  options[:insert] = true
  find_and_modify options
end
is_acquired?() click to toggle source
# File lib/mongo-lock/drivers/base.rb, line 34
def is_acquired?
  find_already_acquired.count > 0
end
key() click to toggle source
# File lib/mongo-lock/drivers/base.rb, line 12
def key
  lock.key
end
query() click to toggle source
# File lib/mongo-lock/drivers/base.rb, line 16
def query
  {
    key: key,
    expires_at: { '$gt' => Time.now }
  }
end