module MasterView class TemplateFileWatcher # Check path for filenames matching filename_pattern and if found # exec block passing in the full path name. # filename_pattern is a wildcard pattern similar to those used in shells # If check_subdirectories is true then the system will recurse into # subdirectories looking for filename matches as well. # returns an array of files that were modified and the block was run for def self.check(path, filename_pattern, check_subdirectories, &block) files_run = [] return unless File.exist?(path) Dir.new(path).each do |f| full_name = File.join(path, f) if File.directory? full_name self.check(full_name, filename_pattern, check_subdirectories, &block) if check_subdirectories && !f.starts_with?('.') elsif File.fnmatch?(filename_pattern, f) mtime = File.mtime(full_name) @@file_mtimes ||= {} unless @@file_mtimes[full_name] == mtime yield full_name @@file_mtimes[full_name] = File.mtime(full_name) files_run << full_name end end end files_run end end end