lib/lockit.rb in lockit-0.0.0 vs lib/lockit.rb in lockit-0.1.1

- old
+ new

@@ -1,23 +1,28 @@ require 'fileutils' module LockIt FILENAME='lock.txt' module Mixin + + # Lock the directory def lock args = {} return false if locked? write_lock args self end + # @param DateTime :release When will this lock likely be released? def revise_lock args return false unless locked? # xxx is it my lock to revise? write_lock args self end + # If the directory is locked already, return false + # Otherwise, lock the directory def try_lock args = {} return false if locked? lock args end @@ -45,10 +50,12 @@ info end private + + # return the path to the closest lock file in this directory def closest_lock_file d = [] last = nil while pwd = File.expand_path(File.join([self.path, d].flatten)) and pwd != last f = File.join(pwd, LockIt::FILENAME) @@ -60,9 +67,10 @@ end def lock_file File.join(self.path, LockIt::FILENAME) end + def write_lock args File.open(lock_file, 'w') do |f| f.write(lock_content(args)) end end