Class: DTAS::Watchable::InotifyReadableIter
- Inherits:
-
SleepyPenguin::Inotify
- Object
- SleepyPenguin::Inotify
- DTAS::Watchable::InotifyReadableIter
- Defined in:
- lib/dtas/watchable.rb
Constant Summary collapse
- FLAGS =
CLOSE_WRITE | MOVED_TO
Class Method Summary collapse
Instance Method Summary collapse
- #readable_iter ⇒ Object
-
#watch_files(paths, blk) ⇒ Object
we must watch the directory, since.
Class Method Details
.new ⇒ Object
12 13 14 |
# File 'lib/dtas/watchable.rb', line 12 def self.new super(:CLOEXEC) end |
Instance Method Details
#readable_iter ⇒ Object
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.(path)) wd = @dir2wd[watchdir] ||= add_watch(watchdir, FLAGS) m = @watches[wd] ||= {} m[watchbase] = true end end |