Class DirectoryWatcher::Scanner
In: lib/directory_watcher/scanner.rb
Parent: Object

The Scanner is responsible for polling the watched directory at a regular interval and generating events when files are modified, added or removed. These events are passed to the DirectoryWatcher which notifies the registered observers.

The Scanner is a pure Ruby class, and as such it works across all Ruby interpreters on the major platforms. This also means that it can be processor intensive for large numbers of files or very fast update intervals. Your mileage will vary, but it is something to keep an eye on.

Methods

join   new   reset   run_once   running?   start   stop  

Attributes

files  [RW] 
glob  [RW] 
interval  [RW] 
stable  [RW] 

Public Class methods

Create a thread-based scanner that will generate file events and pass those events (as an array) to the given block.

Public Instance methods

If the scanner thread is running, the calling thread will suspend execution and run the scanner thread. This method does not return until the scanner thread is stopped or until limit seconds have passed.

If the scanner thread is not running, this method returns immediately with nil.

Reset the scanner state by clearing the stored file list. Passing true to this method will cause the file list to be pre-loaded after it has been cleared effectively skipping the initial round of file added events that would normally be generated.

Performs exactly one scan of the directory for file changes and notifies the observers.

Returns true if the scanner is currently running. Returns false if this is not the case.

Start the scanner thread. If the scanner is already running, this method will return without taking any action.

Stop the scanner thread. If the scanner is already stopped, this method will return without taking any action.

[Validate]