Class: Lock

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

Instance Method Summary collapse

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

#closeObject



18
19
20
21
# File 'lib/nysol/lock.rb', line 18

def close
  @fp.flock(File::LOCK_UN)
  @fp.close()
end

#lockObject



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

def lock
  return @fp.flock(File::LOCK_EX)
end

#removeObject



23
24
25
# File 'lib/nysol/lock.rb', line 23

def remove
  `rm #{@lockfile}`
end

#unlockObject



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

def unlock
  return @fp.flock(File::LOCK_UN)
end