Class: OnetableTerminator::Lock

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(driver) ⇒ Lock

Returns a new instance of Lock.



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

def initialize(driver)
  @filename = "/tmp/onevnm-#{driver}-lock"
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



3
4
5
# File 'lib/onetable_terminator/lock.rb', line 3

def file
  @file
end

#filenameObject (readonly)

Returns the value of attribute filename.



3
4
5
# File 'lib/onetable_terminator/lock.rb', line 3

def filename
  @filename
end

Instance Method Details

#lockObject



9
10
11
12
# File 'lib/onetable_terminator/lock.rb', line 9

def lock
  @file = File.open(filename, 'w')
  file.flock(File::LOCK_EX)
end

#unlockObject



14
15
16
# File 'lib/onetable_terminator/lock.rb', line 14

def unlock
  file.close
end