Sha256: 76b5dae8de4b5b141e8a8df036573a122b94cd383d09c545796e3737ec04578c

Contents?: true

Size: 1.38 KB

Versions: 7

Compression:

Stored size: 1.38 KB

Contents

require 'listen/adapter/base'
require 'listen/adapter/bsd'
require 'listen/adapter/darwin'
require 'listen/adapter/linux'
require 'listen/adapter/polling'
require 'listen/adapter/windows'

module Listen
  module Adapter
    OPTIMIZED_ADAPTERS = [Darwin, Linux, BSD, Windows]
    POLLING_FALLBACK_MESSAGE = 'Listen will be polling for changes.'\
      'Learn more at https://github.com/guard/listen#listen-adapters.'

    def self.select(options = {})
      _log :debug, 'Adapter: considering TCP ...'
      return TCP if options[:force_tcp]
      _log :debug, 'Adapter: considering polling ...'
      return Polling if options[:force_polling]
      _log :debug, 'Adapter: considering optimized backend...'
      return _usable_adapter_class if _usable_adapter_class
      _log :debug, 'Adapter: falling back to polling...'
      _warn_polling_fallback(options)
      Polling
    rescue
      _log :warn, format('Adapter: failed: %s:%s', $ERROR_POSITION.inspect,
                         $ERROR_POSITION * "\n")
      raise
    end

    private

    def self._usable_adapter_class
      OPTIMIZED_ADAPTERS.detect(&:usable?)
    end

    def self._warn_polling_fallback(options)
      msg = options.fetch(:polling_fallback_message, POLLING_FALLBACK_MESSAGE)
      Kernel.warn "[Listen warning]:\n  #{msg}" if msg
    end

    def self._log(type, message)
      Celluloid::Logger.send(type, message)
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
listen-2.10.1 lib/listen/adapter.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/listen-2.8.6/lib/listen/adapter.rb
listen-2.10.0 lib/listen/adapter.rb
listen-2.9.0 lib/listen/adapter.rb
listen-2.8.6 lib/listen/adapter.rb
listen-2.8.5 lib/listen/adapter.rb
listen-2.8.4 lib/listen/adapter.rb