Class: Dply::Lock

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/dply/lock.rb

Instance Method Summary collapse

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

#acquireObject



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_fileObject



17
18
19
# File 'lib/dply/lock.rb', line 17

def lock_file
  @lock_file ||= File.open("#{@dir}/.dply.lock", "a+")
end