forked from paul/rubberin
Rewrite to use the new rb-inotify API
This commit is contained in:
parent
96a6d3533c
commit
712b17c308
15
rubberin
15
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
|
||||
|
|
Loading…
Reference in New Issue