Class: Inotify::Watcher

Inherits:
Object
  • Object
show all
Defined in:
lib/inotify-ffi.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, event_mask) ⇒ Watcher

Returns a new instance of Watcher.



20
21
22
# File 'lib/inotify-ffi.rb', line 20

def initialize(path, event_mask)
  @path, @event_mask = path, event_mask
end

Instance Attribute Details

#ioObject (readonly)

Returns the value of attribute io.



23
24
25
# File 'lib/inotify-ffi.rb', line 23

def io
  @io
end

Class Method Details

.setup(path, event_mask) ⇒ Object



16
17
18
# File 'lib/inotify-ffi.rb', line 16

def self.setup(path, event_mask)
  new(path, event_mask).setup
end

Instance Method Details

#async_each_event(&blk) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/inotify-ffi.rb', line 39

def async_each_event(&blk)
  mod = Module.new do
    include Connection
    define_method(:notify_event, &blk)
  end
  EM.watch(@io, mod) do |c|
    c.notify_readable = true
  end
end

#each_eventObject



32
33
34
35
36
37
# File 'lib/inotify-ffi.rb', line 32

def each_event
  loop do
    ready = IO.select([ @io ], nil, nil, nil)
    yield Inotify.process_event(@fd)
  end
end

#setupObject



25
26
27
28
29
30
# File 'lib/inotify-ffi.rb', line 25

def setup
  @fd = Inotify.init
  @wd = Inotify.add_watch(@fd, @path, @event_mask)
  @io = FFI::IO.for_fd(@fd)
  self
end