# File lib/rerun/watcher.rb, line 18 def initialize(&client_callback) @client_callback = client_callback @sleep_time = 1 @priority = 0 @directories = [] @files = [] @found = nil @first_time = true @thread = nil end
add a directory to be watched @param dir the directory to watch @param expression the glob pattern to search under the watched directory
# File lib/rerun/watcher.rb, line 36 def add_directory(dir, expression="**/*") if FileTest.exists?(dir) && FileTest.readable?(dir) then @directories << Directory.new(dir, expression) else raise InvalidDirectoryError, "Dir '#{dir}' either doesnt exist or isnt readable" end end
add a specific file to the watch list @param file the file to watch
# File lib/rerun/watcher.rb, line 50 def add_file(file) if FileTest.exists?(file) && FileTest.readable?(file) then @files << file else raise InvalidFileError, "File '#{file}' either doesnt exist or isnt readable" end end
wait for the filewatcher to finish
# File lib/rerun/watcher.rb, line 104 def join @thread.join() if @thread rescue Interrupt => e # don't care end
# File lib/rerun/watcher.rb, line 62 def prime @first_time = true @found = Hash.new() examine @first_time = false end
# File lib/rerun/watcher.rb, line 44 def remove_directory(dir) @directories.delete(dir) end
# File lib/rerun/watcher.rb, line 58 def remove_file(file) @files.delete(file) end
# File lib/rerun/watcher.rb, line 69 def start if @thread then raise RuntimeError, "already started" end prime @thread = Thread.new do while true do examine sleep(@sleep_time) end end @thread.priority = @priority at_exit { stop } #? end
kill the filewatcher thread
# File lib/rerun/watcher.rb, line 90 def stop begin @thread.wakeup rescue ThreadError => e # ignore end begin @thread.kill rescue ThreadError => e # ignore end end