Class: DTAS::Watchable::InotifyReadableIter

Inherits:
SleepyPenguin::Inotify
  • Object
show all
Defined in:
lib/dtas/watchable.rb

Constant Summary collapse

FLAGS =
CLOSE_WRITE | MOVED_TO

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.newObject



12
13
14
# File 'lib/dtas/watchable.rb', line 12

def self.new
  super(:CLOEXEC)
end

Instance Method Details

#readable_iterObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dtas/watchable.rb', line 18

def readable_iter
  or_call = false
  while event = take(true) # drain the buffer
    w = @watches[event.wd] or next
    if (event.mask & FLAGS) != 0 && w[event.name]
      or_call = true
    end
  end
  if or_call
    @on_readable.call
    :delete
  else
    :wait_readable
  end
end

#watch_files(paths, blk) ⇒ Object

we must watch the directory, since



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/dtas/watchable.rb', line 35

def watch_files(paths, blk)
  @watches = {} # wd -> { basename -> true }
  @on_readable = blk
  @dir2wd = {}
  Array(paths).each do |path|
    watchdir, watchbase = File.split(File.expand_path(path))
    wd = @dir2wd[watchdir] ||= add_watch(watchdir, FLAGS)
    m = @watches[wd] ||= {}
    m[watchbase] = true
  end
end