Class: Listen::Adapters::Linux

Inherits:
Listen::Adapter show all
Defined in:
lib/listen/adapters/linux.rb

Overview

Listener implementation for Linux ‘inotify`.

Constant Summary

Constants inherited from Listen::Adapter

Listen::Adapter::DEFAULT_LATENCY, Listen::Adapter::POLLING_FALLBACK_MESSAGE

Instance Attribute Summary

Attributes inherited from Listen::Adapter

#latency

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Listen::Adapter

select_and_initialize

Constructor Details

#initialize(directory, options = {}, &callback) ⇒ Linux

Initialize the Adapter. See Listen::Adapter#initialize for more info.



19
20
21
22
23
# File 'lib/listen/adapters/linux.rb', line 19

def initialize(directory, options = {}, &callback)
  super
  @changed_dirs = Set.new
  init_worker
end

Class Method Details

.usable?Boolean

Check if the adapter is usable on the current OS.

Returns:

  • (Boolean)

    whether usable or not



44
45
46
47
48
49
50
51
# File 'lib/listen/adapters/linux.rb', line 44

def self.usable?
  return false unless RbConfig::CONFIG['target_os'] =~ /linux/i

  require 'rb-inotify'
  true
rescue LoadError
  false
end

Instance Method Details

#startObject

Start the adapter.



27
28
29
30
31
# File 'lib/listen/adapters/linux.rb', line 27

def start
  super
  Thread.new { @worker.run }
  poll_changed_dirs
end

#stopObject

Stop the adapter.



35
36
37
38
# File 'lib/listen/adapters/linux.rb', line 35

def stop
  super
  @worker.stop
end