Class: Dply::Lock
Instance Method Summary collapse
- #acquire ⇒ Object
-
#initialize(dir) ⇒ Lock
constructor
A new instance of Lock.
- #lock_file ⇒ Object
Methods included from Helper
#cmd, #error, #git, #logger, #sh, #symlink
Constructor Details
#initialize(dir) ⇒ Lock
Returns a new instance of Lock.
7 8 9 |
# File 'lib/dply/lock.rb', line 7 def initialize(dir) @dir = dir end |
Instance Method Details
#acquire ⇒ Object
11 12 13 14 15 |
# File 'lib/dply/lock.rb', line 11 def acquire logger.debug "acquiring lock" lock_acquired = lock_file.flock(File::LOCK_NB | File::LOCK_EX) error "exclusive lock not available" if not lock_acquired end |
#lock_file ⇒ Object
17 18 19 |
# File 'lib/dply/lock.rb', line 17 def lock_file @lock_file ||= File.open("#{@dir}/.dply.lock", "a+") end |