Class: Uc::Lock

Inherits:
Object
  • Object
show all
Defined in:
lib/uc/lock.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_dir) ⇒ Lock

Returns a new instance of Lock.



6
7
8
# File 'lib/uc/lock.rb', line 6

def initialize(app_dir)
  @app_dir = app_dir
end

Instance Attribute Details

#app_dirObject (readonly)

Returns the value of attribute app_dir.



5
6
7
# File 'lib/uc/lock.rb', line 5

def app_dir
  @app_dir
end

Instance Method Details

#acquireObject



10
11
12
13
14
15
# File 'lib/uc/lock.rb', line 10

def acquire
  Dir.chdir app_dir do
    lock_acquired = File.new("tmp/.uc.lock", "a+").flock( File::LOCK_NB | File::LOCK_EX )
    raise ::Uc::Error,"another uc process is already running"  if not lock_acquired
  end
end