Class: FunWith::Files::Watchers::FileWatcher
- Inherits:
-
NodeWatcher
- Object
- NodeWatcher
- FunWith::Files::Watchers::FileWatcher
- Defined in:
- lib/fun_with/files/watchers/file_watcher.rb
Instance Attribute Summary collapse
-
#last_modified ⇒ Object
Returns the value of attribute last_modified.
Attributes inherited from NodeWatcher
Instance Method Summary collapse
-
#all_paths ⇒ Object
returns all paths below it in the hierarchy, including the path of the node itself.
- #deleted? ⇒ Boolean
-
#initialize(path) ⇒ FileWatcher
constructor
A new instance of FileWatcher.
- #modified? ⇒ Boolean
- #refresh_last_modified ⇒ Object
- #update ⇒ Object
Methods inherited from NodeWatcher
#create_watchers, #new_changeset, #set_path
Constructor Details
#initialize(path) ⇒ FileWatcher
Returns a new instance of FileWatcher.
8 9 10 11 |
# File 'lib/fun_with/files/watchers/file_watcher.rb', line 8 def initialize( path ) set_path( path ) refresh_last_modified end |
Instance Attribute Details
#last_modified ⇒ Object
Returns the value of attribute last_modified.
6 7 8 |
# File 'lib/fun_with/files/watchers/file_watcher.rb', line 6 def last_modified @last_modified end |
Instance Method Details
#all_paths ⇒ Object
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.
39 40 41 |
# File 'lib/fun_with/files/watchers/file_watcher.rb', line 39 def all_paths [self.path] end |
#deleted? ⇒ Boolean
21 22 23 |
# File 'lib/fun_with/files/watchers/file_watcher.rb', line 21 def deleted? ! self.path.exist? end |
#modified? ⇒ Boolean
17 18 19 |
# File 'lib/fun_with/files/watchers/file_watcher.rb', line 17 def modified? self.path.exist? && self.last_modified < self.path.stat.mtime end |
#refresh_last_modified ⇒ Object
13 14 15 |
# File 'lib/fun_with/files/watchers/file_watcher.rb', line 13 def refresh_last_modified self.last_modified = self.path.stat.mtime if self.path.exist? end |
#update ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/fun_with/files/watchers/file_watcher.rb', line 25 def update if deleted? { self.path => :deleted } elsif modified? refresh_last_modified { self.path => :modified } else {} end end |