Class: EMDirWatcher::Platform::Linux::Watcher

Inherits:
Object
  • Object
show all
Defined in:
lib/em-dir-watcher/platform/linux.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, inclusions, exclusions) ⇒ Watcher

Returns a new instance of Watcher.


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/em-dir-watcher/platform/linux.rb', line 16

def initialize path, inclusions, exclusions
  @notifier = INotify::Notifier.new

  @notifier.watch(path, :recursive, :attrib, :modify, :create,
                  :delete, :delete_self, :moved_from, :moved_to,
                  :move_self) do |event|
    yield event.absolute_name
  end

  @conn = EM.watch @notifier.to_io do |conn|
    class << conn
      attr_accessor :notifier

      def notify_readable
        @notifier.process
      end
    end
    conn.notifier = @notifier
    conn.notify_readable = true
  end
end

Instance Method Details

#ready_to_use?Boolean

Returns:

  • (Boolean)

42
# File 'lib/em-dir-watcher/platform/linux.rb', line 42

def ready_to_use?; true; end

#stopObject


44
45
46
# File 'lib/em-dir-watcher/platform/linux.rb', line 44

def stop
  Native.close @notifier.fd
end

#when_ready_to_useObject


38
39
40
# File 'lib/em-dir-watcher/platform/linux.rb', line 38

def when_ready_to_use
    yield
end