Methods

DirectoryWatcher::RevScanner

The RevScanner uses the Rev loop to monitor changes to files in the watched directory. This scanner is more efficient than the pure Ruby scanner because it relies on the operating system kernel notifictions instead of a periodic polling and stat of every file in the watched directory (the technique used by the Scanner class).

Public Class Methods

new { |events| block } click to toggle source

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

# File lib/directory_watcher/rev_scanner.rb, line 25
def initialize( &block )
  super(&block)
  @watchers = {}
end

Public Instance Methods

start() click to toggle source

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

# File lib/directory_watcher/rev_scanner.rb, line 33
def start
  return if running?

  @timer = Timer.new self
  @thread = Thread.new {
    rev_loop = Thread.current._rev_loop
    @files.keys.each do |fn|
      if test ee, fn
        _watch_file fn
        next
      end

      @files.delete fn
      @events << ::DirectoryWatcher::Event.new(:removed, fn)
    end

    @timer.attach rev_loop
    rev_loop.run
  }
end
stop() click to toggle source

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

# File lib/directory_watcher/rev_scanner.rb, line 57
def stop
  return unless running?

  @timer.detach
  @timer = nil

  @watchers.each_value {|w| w.detach}
  @watchers.clear

  notify

  @thread._rev_loop.stop rescue nil
  @thread.kill    # for some reason the rev loop is not returning after stopping
  @thread = nil
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.