Sha256: 1fa5cc04f425171046f5278309b59add39f0f6e4fedd9d486487e5108f4c92f2

Contents?: true

Size: 905 Bytes

Versions: 9

Compression:

Stored size: 905 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
        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

9 entries across 9 versions & 1 rubygems

Version Path
listen-2.1.0 lib/listen/adapter/darwin.rb
listen-2.0.4 lib/listen/adapter/darwin.rb
listen-2.0.3 lib/listen/adapter/darwin.rb
listen-2.0.2 lib/listen/adapter/darwin.rb
listen-2.0.1 lib/listen/adapter/darwin.rb
listen-2.0.0 lib/listen/adapter/darwin.rb
listen-2.0.0.pre.1 lib/listen/adapter/darwin.rb
listen-2.0.0.beta.2 lib/listen/adapter/darwin.rb
listen-2.0.0.beta.1 lib/listen/adapter/darwin.rb