Class: Mongo::Lock::Drivers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/mongo-lock/drivers/base.rb

Direct Known Subclasses

Mongo, Moped

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lock) ⇒ Base

Returns a new instance of Base.



8
9
10
# File 'lib/mongo-lock/drivers/base.rb', line 8

def initialize lock
  self.lock = lock
end

Instance Attribute Details

#lockObject

Returns the value of attribute lock.



6
7
8
# File 'lib/mongo-lock/drivers/base.rb', line 6

def lock
  @lock
end

Instance Method Details

#find_and_update(time, options) ⇒ Object



29
30
31
32
# 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) ⇒ Object



23
24
25
26
27
# 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?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/mongo-lock/drivers/base.rb', line 34

def is_acquired?
  find_already_acquired.count > 0
end

#keyObject



12
13
14
# File 'lib/mongo-lock/drivers/base.rb', line 12

def key
  lock.key
end

#queryObject



16
17
18
19
20
21
# File 'lib/mongo-lock/drivers/base.rb', line 16

def query
  {
    key: key,
    expires_at: { '$gt' => Time.now }
  }
end