Sha256: ba0901efc5c45a6f31e40d746197c5204708438403bf46c98bf5969bd2749f41

Contents?: true

Size: 1.16 KB

Versions: 16

Compression:

Stored size: 1.16 KB

Contents

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

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
masterview-0.0.11 lib/masterview/extras/watcher.rb
masterview-0.0.14 lib/masterview/extras/watcher.rb
masterview-0.0.10 lib/masterview/extras/watcher.rb
masterview-0.0.12 lib/masterview/extras/watcher.rb
masterview-0.0.13 lib/masterview/extras/watcher.rb
masterview-0.0.15 lib/masterview/extras/watcher.rb
masterview-0.0.16 lib/masterview/extras/watcher.rb
masterview-0.0.17 lib/masterview/extras/watcher.rb
masterview-0.0.2 lib/masterview/extras/watcher.rb
masterview-0.0.8 lib/masterview/extras/watcher.rb
masterview-0.0.9 lib/masterview/extras/watcher.rb
masterview-0.0.7 lib/masterview/extras/watcher.rb
masterview_parser-0.0.6 lib/masterview/extras/watcher.rb
masterview_parser-0.0.5 lib/masterview/extras/watcher.rb
masterview_parser-0.0.3 lib/masterview/extras/watcher.rb
masterview_parser-0.0.4 lib/masterview/extras/watcher.rb