Sha256: 2850f09d2d038f85e985019202e919e3aa399fea638d1671db7ad4e2ec79eefc

Contents?: true

Size: 1.33 KB

Versions: 8

Compression:

Stored size: 1.33 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#polling-fallback.'

    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, "Adapter: failed: #{$!.inspect}:#{$@.join("\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

8 entries across 6 versions & 3 rubygems

Version Path
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/listen-2.7.9/lib/listen/adapter.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/listen-2.7.9/lib/listen/adapter.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/listen-2.7.9/lib/listen/adapter.rb
vagrant-tiktalik-0.0.3 vendor/bundle/ruby/2.0.0/gems/listen-2.7.9/lib/listen/adapter.rb
listen-2.7.9 lib/listen/adapter.rb
listen-2.7.8 lib/listen/adapter.rb
listen-2.7.7 lib/listen/adapter.rb
listen-2.7.6 lib/listen/adapter.rb