Class: MasterView::TemplateFileWatcher
- Inherits:
-
Object
- Object
- MasterView::TemplateFileWatcher
- Defined in:
- lib/masterview/extras/watcher.rb
Class Method Summary collapse
-
.check(path, filename_pattern, check_subdirectories, &block) ⇒ Object
Check path for filenames matching filename_pattern and if found exec block passing in the full path name.
Class Method Details
.check(path, filename_pattern, check_subdirectories, &block) ⇒ Object
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
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/masterview/extras/watcher.rb', line 9 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 |