Class: Mongo::Lock::Drivers::Base
- Inherits:
-
Object
- Object
- Mongo::Lock::Drivers::Base
- Defined in:
- lib/mongo-lock/drivers/base.rb
Instance Attribute Summary collapse
-
#lock ⇒ Object
Returns the value of attribute lock.
Instance Method Summary collapse
- #find_and_update(time, options) ⇒ Object
- #find_or_insert(options) ⇒ Object
-
#initialize(lock) ⇒ Base
constructor
A new instance of Base.
- #is_acquired? ⇒ Boolean
- #key ⇒ Object
- #query ⇒ Object
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
#lock ⇒ Object
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, [:expire_at] = lock.expires_at + time find_and_modify end |
#find_or_insert(options) ⇒ Object
23 24 25 26 27 |
# File 'lib/mongo-lock/drivers/base.rb', line 23 def find_or_insert [:expire_at] = Time.now + [:expire_in] [:insert] = true find_and_modify end |
#is_acquired? ⇒ Boolean
34 35 36 |
# File 'lib/mongo-lock/drivers/base.rb', line 34 def is_acquired? find_already_acquired.count > 0 end |
#key ⇒ Object
12 13 14 |
# File 'lib/mongo-lock/drivers/base.rb', line 12 def key lock.key end |
#query ⇒ Object
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 |