Class: Morlock
- Inherits:
-
Object
- Object
- Morlock
- Defined in:
- lib/morlock/base.rb,
lib/morlock/rails.rb,
lib/morlock/version.rb,
lib/morlock/gem_client.rb
Defined Under Namespace
Classes: DalliGemClient, GemClient, MemcacheGemClient, MorlockRailtie, TestGemClient, UnknownGemClient
Constant Summary collapse
- DEFAULT_EXPIRATION =
60
- VERSION =
"0.0.7"
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Instance Method Summary collapse
-
#initialize(client) ⇒ Morlock
constructor
A new instance of Morlock.
- #lock(key, options = {}) ⇒ Object
Constructor Details
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
6 7 8 |
# File 'lib/morlock/base.rb', line 6 def client @client end |
Instance Method Details
#lock(key, options = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/morlock/base.rb', line 12 def lock(key, = {}) lock_obtained = @client.add(key, [:expiration] || DEFAULT_EXPIRATION) puts "Lock for #{key} #{lock_obtained ? "obtained" : "not obtained"}." if [:verbose] yield if lock_obtained && block_given? [:success].call if lock_obtained && [:success] [:failure].call if !lock_obtained && [:failure] lock_obtained ensure if lock_obtained if @client.delete(key) puts "Lock removed for #{key}" if [:verbose] else puts "Someone else removed the lock for #{key}!" if [:verbose] end end end |