From 712b17c30891f60a54fb34219801c4c606a9a84f Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Fri, 22 Jun 2018 20:07:26 +0200 Subject: [PATCH] Rewrite to use the new rb-inotify API --- rubberin | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/rubberin b/rubberin index 4b3c91b..3fb521d 100755 --- a/rubberin +++ b/rubberin @@ -186,20 +186,15 @@ end ## Main event loop # Add input file with dependancies to the watch list and start event loop. -i = INotify::Notifier.new +notifier = INotify::Notifier.new dirs = files.map { |file| File.dirname(file) } -dirmap = {} dirs.each do |dir| - # Use a watch descriptor per directory and save it for later. - wd = i.add_watch(dir, Inotify::CLOSE_WRITE) - dirmap[wd] = dir -end -# Process the events, recompile and reload when necessary. -i.each_event do |ev| - # Only recompile if files are modified that we are interested in. - if files.include?(dirmap[ev.wd] + "/" + ev.name) + # Set up a watch per directory + notifier.watch(dir, :close_write) do puts "I: file #{ev.name} modified, compiling #{infile}..." compile(infile, mode) reload(infile, mode) end end + +notifier.run