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

- old
+ new

@@ -1,25 +1,25 @@ class Knj::Event_filemod - attr_reader :args - - def initialize(args, &block) - @args = args - @run = true - @mutex = Mutex.new - - @args[:wait] = 1 if !@args.key?(:wait) - - @mtimes = {} - args[:paths].each do |path| - @mtimes[path] = File.mtime(path) - end - - Knj::Thread.new do - while @run do - break if !@args or !@args[:paths] or @args[:paths].empty? - - @mutex.synchronize do + attr_reader :args + + def initialize(args, &block) + @args = args + @run = true + @mutex = Mutex.new + + @args[:wait] = 1 if !@args.key?(:wait) + + @mtimes = {} + args[:paths].each do |path| + @mtimes[path] = File.mtime(path) + end + + 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.key?(path) and @mtimes.is_a?(Hash) @mtimes[path] = File.mtime(path) @@ -42,19 +42,19 @@ end end sleep @args[:wait] if @args and @run end - end - end - end - - def destroy - @mtimes = {} - @run = false - @args = nil - end - - def add_path(fpath) + end + end + end + + def destroy + @mtimes = {} + @run = false + @args = nil + end + + def add_path(fpath) @args[:paths] << fpath - end + end end \ No newline at end of file