Module: Listen::Adapter

Defined in:
lib/listen/adapter.rb,
lib/listen/adapter/bsd.rb,
lib/listen/adapter/base.rb,
lib/listen/adapter/linux.rb,
lib/listen/adapter/darwin.rb,
lib/listen/adapter/polling.rb,
lib/listen/adapter/windows.rb

Defined Under Namespace

Classes: BSD, Base, Darwin, Linux, Polling, Windows

Constant Summary collapse

OPTIMIZED_ADAPTERS =
%w[Darwin Linux BSD Windows]
POLLING_FALLBACK_MESSAGE =
"Listen will be polling for changes. Learn more at https://github.com/guard/listen#polling-fallback."

Class Method Summary collapse

Class Method Details

._select(options) ⇒ Object (private)



20
21
22
23
24
25
26
# File 'lib/listen/adapter.rb', line 20

def self._select(options)
  return Polling if options[:force_polling] || not_mri?
  return _usable_adapter_class if _usable_adapter_class

  _warn_polling_fallback(options)
  Polling
end

._usable_adapter_classObject (private)



28
29
30
31
# File 'lib/listen/adapter.rb', line 28

def self._usable_adapter_class
  adapters = OPTIMIZED_ADAPTERS.map { |adapter| Adapter.const_get(adapter) }
  adapters.detect { |adapter| adapter.send(:usable?) }
end

._warn_polling_fallback(options) ⇒ Object (private)



33
34
35
36
37
38
# File 'lib/listen/adapter.rb', line 33

def self._warn_polling_fallback(options)
  return if options[:polling_fallback_message] == false

  warning = options.fetch(:polling_fallback_message, POLLING_FALLBACK_MESSAGE)
  Kernel.warn "[Listen warning]:\n#{warning.gsub(/^(.*)/, '  \1')}"
end

.new(listener) ⇒ Object



13
14
15
16
# File 'lib/listen/adapter.rb', line 13

def self.new(listener)
  adapter_class = _select(listener.options)
  adapter_class.new(listener)
end

.not_mri?Boolean (private)

Returns:

  • (Boolean)


40
41
42
# File 'lib/listen/adapter.rb', line 40

def self.not_mri?
  RUBY_ENGINE != 'ruby'
end