Class: DirectoryWatcher::RevScanner::Watcher
- Inherits:
-
Rev::StatWatcher
- Object
- Rev::StatWatcher
- DirectoryWatcher::RevScanner::Watcher
- Defined in:
- lib/directory_watcher/rev_scanner.rb
Overview
:stopdoc:
Watch files using the Rev::StatWatcher.
The rev 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 ⇒ Object
Rev uses on_change so we convert that to the appropriate EventableScanner calls.
Constructor Details
#initialize(fn, scanner) ⇒ Watcher
Returns a new instance of Watcher.
82 83 84 85 86 87 88 89 90 |
# File 'lib/directory_watcher/rev_scanner.rb', line 82 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
78 79 80 |
# File 'lib/directory_watcher/rev_scanner.rb', line 78 def self.watch(fn, scanner ) new(fn, scanner) end |
Instance Method Details
#on_change ⇒ Object
Rev uses on_change so we convert that to the appropriate EventableScanner calls. Unlike Coolio, Rev’s on_change() takes no parameters
96 97 98 99 100 101 102 103 |
# File 'lib/directory_watcher/rev_scanner.rb', line 96 def on_change if File.exist?(path) then @scanner.on_removed(self, ::DirectoryWatcher::FileStat.for_removed_path(path)) else stat = File.stat(path) @scanner.on_modified(self, ::DirectoryWatcher::FileStat.new(path, stat.mtime, stat.size)) end end |