Class: DirectoryWatcher::CoolioScanner::Watcher
- Inherits:
-
Coolio::StatWatcher
- Object
- Coolio::StatWatcher
- DirectoryWatcher::CoolioScanner::Watcher
- Defined in:
- lib/directory_watcher/coolio_scanner.rb
Overview
:stopdoc:
Watch files using the Coolio StatWatcher.
This class is required by EventableScanner to institute file watching.
The coolio on_change
callback is converted to the appropriate on_removed
and on_modified
callbacks for the EventableScanner.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(fn, scanner) ⇒ Watcher
constructor
A new instance of Watcher.
-
#on_change(prev_stat, current_stat) ⇒ Object
Cool.io uses on_change so we convert that to the appropriate EventableScanner calls.
Constructor Details
#initialize(fn, scanner) ⇒ Watcher
Returns a new instance of Watcher.
78 79 80 81 82 83 84 85 86 |
# File 'lib/directory_watcher/coolio_scanner.rb', line 78 def initialize( fn, scanner ) # for file watching, we want to make sure this happens at a reasonable # value, so set it to 0 if the scanner.interval is > 5 seconds. This will # make it use the system value, and allow us to test. i = scanner.interval < 5 ? scanner.interval : 0 super(fn, i) @scanner = scanner attach(scanner.event_loop) end |
Class Method Details
.watch(fn, scanner) ⇒ Object
74 75 76 |
# File 'lib/directory_watcher/coolio_scanner.rb', line 74 def self.watch(fn, scanner ) new(fn, scanner) end |
Instance Method Details
#on_change(prev_stat, current_stat) ⇒ Object
Cool.io uses on_change so we convert that to the appropriate EventableScanner calls.
91 92 93 94 95 96 97 98 |
# File 'lib/directory_watcher/coolio_scanner.rb', line 91 def on_change( prev_stat, current_stat ) logger.debug "on_change called" if File.exist?(path) then @scanner.on_modified(self, ::DirectoryWatcher::FileStat.new(path, current_stat.mtime, current_stat.size)) else @scanner.on_removed(self, ::DirectoryWatcher::FileStat.for_removed_path(path)) end end |