lib/knj/event_filemod.rb in knjrbfw-0.0.7 vs lib/knj/event_filemod.rb in knjrbfw-0.0.8

- old
+ new

@@ -4,11 +4,11 @@ def initialize(args, &block) @args = args @run = true @mutex = Mutex.new - @args[:wait] = 1 if !@args.has_key?(:wait) + @args[:wait] = 1 if !@args.key?(:wait) @mtimes = {} args[:paths].each do |path| @mtimes[path] = File.mtime(path) end @@ -16,34 +16,35 @@ Knj::Thread.new do while @run do break if !@args or !@args[:paths] or @args[:paths].empty? @mutex.synchronize do - @args[:paths].each do |path| - changed = false - - if @mtimes and !@mtimes.has_key?(path) and @mtimes.is_a?(Hash) - @mtimes[path] = File.mtime(path) - end - - begin - newdate = File.mtime(path) - rescue Errno::ENOENT - #file does not exist. - changed = true - end - - if !changed and newdate and @mtimes and newdate > @mtimes[path] - changed = true - end - - if changed - block.call(self, path) - @args[:paths].delete(path) if @args and @args[:break_when_changed] - end - end - - sleep @args[:wait] if @args and @run + @args[:paths].each do |path| + changed = false + + if @mtimes and !@mtimes.key?(path) and @mtimes.is_a?(Hash) + @mtimes[path] = File.mtime(path) + end + + begin + newdate = File.mtime(path) + rescue Errno::ENOENT + #file does not exist. + changed = true + end + + if !changed and newdate and @mtimes and newdate > @mtimes[path] + changed = true + end + + if changed + block.call(self, path) + @args[:paths].delete(path) if @args and @args[:break_when_changed] + end + end + + sleep @args[:wait] if @args and @run + end end end end def destroy \ No newline at end of file