Class: Lock
- Inherits:
-
Object
- Object
- Lock
- Defined in:
- lib/nysol/lock.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(rsc, mode = "w") ⇒ Lock
constructor
A new instance of Lock.
- #lock ⇒ Object
- #remove ⇒ Object
- #unlock ⇒ Object
Constructor Details
#initialize(rsc, mode = "w") ⇒ Lock
Returns a new instance of Lock.
5 6 7 8 |
# File 'lib/nysol/lock.rb', line 5 def initialize(rsc, mode="w") @lockfile = "/tmp/#{rsc}.lock" @fp = open(@lockfile, mode) end |
Instance Method Details
#close ⇒ Object
18 19 20 21 |
# File 'lib/nysol/lock.rb', line 18 def close @fp.flock(File::LOCK_UN) @fp.close() end |
#lock ⇒ Object
10 11 12 |
# File 'lib/nysol/lock.rb', line 10 def lock return @fp.flock(File::LOCK_EX) end |
#remove ⇒ Object
23 24 25 |
# File 'lib/nysol/lock.rb', line 23 def remove `rm #{@lockfile}` end |
#unlock ⇒ Object
14 15 16 |
# File 'lib/nysol/lock.rb', line 14 def unlock return @fp.flock(File::LOCK_UN) end |