Sha256: 5e44ee41ebaf54cfa82c036f41db2575e8c33e904796ea532eb79cda77fac72b

Contents?: true

Size: 1.33 KB

Versions: 95

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

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].freeze
    POLLING_FALLBACK_MESSAGE = 'Listen will be polling for changes.'\
      'Learn more at https://github.com/guard/listen#listen-adapters.'

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

      private

      def _usable_adapter_class
        OPTIMIZED_ADAPTERS.find(&:usable?)
      end

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

Version data entries

95 entries across 94 versions & 6 rubygems

Version Path
harbr-0.1.49 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/adapter.rb
harbr-0.1.48 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/adapter.rb
harbr-0.1.47 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/adapter.rb
harbr-0.1.46 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/adapter.rb
harbr-0.1.45 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/adapter.rb
harbr-0.1.44 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/adapter.rb
harbr-0.1.43 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/adapter.rb
harbr-0.1.42 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/adapter.rb
harbr-0.1.41 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/adapter.rb
harbr-0.1.39 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/adapter.rb
harbr-0.1.38 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/adapter.rb
harbr-0.1.37 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/adapter.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/adapter.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/listen-3.8.0/lib/listen/adapter.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/adapter.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/adapter.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/adapter.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/adapter.rb
listen-3.8.0 lib/listen/adapter.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/listen-3.7.1/lib/listen/adapter.rb