Class: OnetableTerminator::Lock
- Inherits:
-
Object
- Object
- OnetableTerminator::Lock
- Defined in:
- lib/onetable_terminator/lock.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
-
#initialize(driver) ⇒ Lock
constructor
A new instance of Lock.
- #lock ⇒ Object
- #unlock ⇒ Object
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
#file ⇒ Object (readonly)
Returns the value of attribute file.
3 4 5 |
# File 'lib/onetable_terminator/lock.rb', line 3 def file @file end |
#filename ⇒ Object (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
#lock ⇒ Object
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 |
#unlock ⇒ Object
14 15 16 |
# File 'lib/onetable_terminator/lock.rb', line 14 def unlock file.close end |