Sha256: dc15c38357ce40d6cc9881c1dd0af938d257e27fbe7731ca7ab4ff72433e624a

Contents?: true

Size: 920 Bytes

Versions: 15

Compression:

Stored size: 920 Bytes

Contents

module Listen
  module Adapter

    # Adapter implementation for Mac OS X `FSEvents`.
    #
    class Darwin < Base

      def self.usable?
        RbConfig::CONFIG['target_os'] =~ /darwin(1.+)?$/i
      end

      def initialize(listener)
        require 'rb-fsevent'
        super
      end

      def start
        worker = _init_worker
        Thread.new { worker.run }
      end

      private

      # Initializes a FSEvent worker and adds a watcher for
      # each directory listened.
      #
      def _init_worker
        FSEvent.new.tap do |worker|
          worker.watch(_directories_path, latency: _latency) do |changes|
            _changes_path(changes).each { |path| _notify_change(path, type: 'Dir') }
          end
        end
      end

      def _changes_path(changes)
        changes.map do |path|
          path.sub!(/\/$/, '')
          Pathname.new(path)
        end
      end
    end

  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
listen-2.7.4 lib/listen/adapter/darwin.rb
listen-2.7.3 lib/listen/adapter/darwin.rb
listen-2.7.2 lib/listen/adapter/darwin.rb
listen-2.7.1 lib/listen/adapter/darwin.rb
listen-2.7.0 lib/listen/adapter/darwin.rb
listen-2.6.2 lib/listen/adapter/darwin.rb
listen-2.6.1 lib/listen/adapter/darwin.rb
listen-2.6.0 lib/listen/adapter/darwin.rb
listen-2.5.0 lib/listen/adapter/darwin.rb
listen-2.4.1 lib/listen/adapter/darwin.rb
listen-2.4.0 lib/listen/adapter/darwin.rb
listen-2.3.1 lib/listen/adapter/darwin.rb
listen-2.2.0 lib/listen/adapter/darwin.rb
listen-2.1.2 lib/listen/adapter/darwin.rb
listen-2.1.1 lib/listen/adapter/darwin.rb