Class: Tango::DatabaseLocker
- Inherits:
-
Object
- Object
- Tango::DatabaseLocker
- Defined in:
- lib/tango/database_locker.rb
Overview
Database locker in form of .lock file
Instance Attribute Summary collapse
-
#lock_path ⇒ Object
readonly
Returns the value of attribute lock_path.
Instance Method Summary collapse
-
#initialize(candidates = [], lock_path = "./tmp/database.lock") ⇒ Tango::DatabaseLocker
constructor
Constructor of DatabaseLocker.
-
#lock(database) ⇒ Tango::DatabaseLocker
Lock given database.
-
#unlocked ⇒ Object
Return name of unlocked database.
Constructor Details
#initialize(candidates = [], lock_path = "./tmp/database.lock") ⇒ Tango::DatabaseLocker
Constructor of DatabaseLocker
15 16 17 18 |
# File 'lib/tango/database_locker.rb', line 15 def initialize( candidates = [], lock_path = "./tmp/database.lock" ) @candidates = candidates @lock_path = lock_path end |
Instance Attribute Details
#lock_path ⇒ Object (readonly)
Returns the value of attribute lock_path.
8 9 10 |
# File 'lib/tango/database_locker.rb', line 8 def lock_path @lock_path end |
Instance Method Details
#lock(database) ⇒ Tango::DatabaseLocker
Lock given database
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tango/database_locker.rb', line 36 def lock( database ) @unlocked = nil File.open( lock_path, "w" ) do |f| f.write( database ) end self end |
#unlocked ⇒ Object
Return name of unlocked database
return [String]
23 24 25 |
# File 'lib/tango/database_locker.rb', line 23 def unlocked @unlocked ||= find_unlocked end |