Sha256: 9c4fb9b1aaab5edd828335eb63510582981199b93305f0cc786088a8cfe4f2b3

Contents?: true

Size: 1.13 KB

Versions: 5

Compression:

Stored size: 1.13 KB

Contents

module Guard

  # Listener implementation for Windows `fchange`.
  #
  class Windows < Listener

    # Initialize the Listener.
    #
    def initialize(*)
      super
      @fchange = FChange::Notifier.new
    end

    # Start the listener.
    #
    def start
      super
      worker.run
    end

    # Stop the listener.
    #
    def stop
      super
      worker.stop
    end

    # Check if the listener is usable on the current OS.
    #
    # @return [Boolean] whether usable or not
    #
    def self.usable?
      require 'rb-fchange'
      true
    rescue LoadError
      UI.info 'Please install rb-fchange gem for Windows file events support'
      false
    end

    private

    # Watch the given directory for file changes.
    #
    # @param [String] directory the directory to watch
    #
    def watch(directory)
      worker.watch(directory, :all_events, :recursive) do |event|
        paths = [File.expand_path(event.watcher.path)]
        files = modified_files(paths, :all => true)
        @callback.call(files) unless files.empty?
      end
    end

    # Get the listener worker.
    #
    def worker
      @fchange
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
guard-0.8.8 lib/guard/listeners/windows.rb
guard-0.8.7 lib/guard/listeners/windows.rb
guard-0.8.6 lib/guard/listeners/windows.rb
guard-0.8.5 lib/guard/listeners/windows.rb
guard-0.8.1 lib/guard/listeners/windows.rb