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