Sha256: 6f8a8aac37ead0c491effd648251033f31996c5bc5ade5228ad67d5cf508645e

Contents?: true

Size: 1.89 KB

Versions: 204

Compression:

Stored size: 1.89 KB

Contents

require 'set'

module Listen
  module Adapters

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

      # Initializes the Adapter. See {Listen::Adapter#initialize} for more info.
      #
      def initialize(directories, options = {}, &callback)
        super
        @worker = init_worker
      end

      # Starts the adapter.
      #
      # @param [Boolean] blocking whether or not to block the current thread after starting
      #
      def start(blocking = true)
        @mutex.synchronize do
          return if @stop == false
          super
        end

        @worker_thread = Thread.new { @worker.run }
        @poll_thread   = Thread.new { poll_changed_dirs(true) }
        @poll_thread.join if blocking
      end

      # Stops the adapter.
      #
      def stop
        @mutex.synchronize do
          return if @stop == true
          super
        end

        @worker.stop
        Thread.kill(@worker_thread) if @worker_thread
        @poll_thread.join
      end

      # Checks if the adapter is usable on the current OS.
      #
      # @return [Boolean] whether usable or not
      #
      def self.usable?
        return false unless RbConfig::CONFIG['target_os'] =~ /mswin|mingw/i

        require 'rb-fchange'
        true
      rescue LoadError
        false
      end

    private

      # Initializes a FChange worker and adds a watcher for
      # each directory passed to the adapter.
      #
      # @return [FChange::Notifier] initialized worker
      #
      def init_worker
        FChange::Notifier.new.tap do |worker|
          @directories.each do |directory|
            worker.watch(directory, :all_events, :recursive) do |event|
              next if @paused
              @mutex.synchronize do
                @changed_dirs << File.expand_path(event.watcher.path)
              end
            end
          end
        end
      end

    end

  end
end

Version data entries

204 entries across 114 versions & 5 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/sass-3.1.19/vendor/listen/lib/listen/adapters/windows.rb
classiccms-0.7.5 vendor/bundle/gems/sass-3.1.17/vendor/listen/lib/listen/adapters/windows.rb
classiccms-0.7.5 vendor/bundle/gems/sass-3.1.18/vendor/listen/lib/listen/adapters/windows.rb
classiccms-0.7.4 vendor/bundle/gems/sass-3.1.19/vendor/listen/lib/listen/adapters/windows.rb
classiccms-0.7.4 vendor/bundle/gems/sass-3.1.17/vendor/listen/lib/listen/adapters/windows.rb
classiccms-0.7.4 vendor/bundle/gems/sass-3.1.18/vendor/listen/lib/listen/adapters/windows.rb
classiccms-0.7.3 vendor/bundle/gems/sass-3.1.18/vendor/listen/lib/listen/adapters/windows.rb
classiccms-0.7.3 vendor/bundle/gems/sass-3.1.17/vendor/listen/lib/listen/adapters/windows.rb
classiccms-0.7.3 vendor/bundle/gems/sass-3.1.19/vendor/listen/lib/listen/adapters/windows.rb
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/sass-3.2.5/vendor/listen/lib/listen/adapters/windows.rb
classiccms-0.7.2 vendor/bundle/gems/sass-3.1.17/vendor/listen/lib/listen/adapters/windows.rb
classiccms-0.7.2 vendor/bundle/gems/sass-3.1.18/vendor/listen/lib/listen/adapters/windows.rb
classiccms-0.7.2 vendor/bundle/gems/sass-3.1.19/vendor/listen/lib/listen/adapters/windows.rb
classiccms-0.7.1 vendor/bundle/gems/sass-3.1.19/vendor/listen/lib/listen/adapters/windows.rb
classiccms-0.7.1 vendor/bundle/gems/sass-3.1.17/vendor/listen/lib/listen/adapters/windows.rb
classiccms-0.7.1 vendor/bundle/gems/sass-3.1.18/vendor/listen/lib/listen/adapters/windows.rb
active_mailer-0.0.9 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/sass-3.2.5/vendor/listen/lib/listen/adapters/windows.rb
active_mailer-0.0.8 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/sass-3.2.5/vendor/listen/lib/listen/adapters/windows.rb
active_mailer-0.0.7 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/sass-3.2.5/vendor/listen/lib/listen/adapters/windows.rb
active_mailer-0.0.6 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/sass-3.2.5/vendor/listen/lib/listen/adapters/windows.rb