Sha256: 98540d7da4fce2383868c60a3df74f733532a710171931437e2e1e69bdb3e18f

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

   
module FunWith
  module Files
    module Watchers
      class FileWatcher < NodeWatcher
        attr_accessor :last_modified
      
        def initialize( path )
          set_path( path )
          refresh_last_modified
        end
      
        def refresh_last_modified
          self.last_modified = self.path.stat.mtime if self.path.exist?
        end
      
        def modified?
          self.path.exist? && self.last_modified < self.path.stat.mtime
        end
      
        def deleted?
          ! self.path.exist?
        end
      
        def update
          if deleted?
            { self.path => :deleted }
          elsif modified?
            refresh_last_modified
            { self.path => :modified }
          else
            {}
          end
        end
        
        # returns all paths below it in the hierarchy, including 
        # the path of the node itself.  In this case, there's
        # only one path to return.
        def all_paths
          [self.path]
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fun_with_files-0.0.18 ./lib/fun_with/files/watchers/file_watcher.rb