From 8a1ca41626839d13200923e051c395094fd5b6cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Re=CC=81my=20Coutable?= Date: Thu, 21 Jul 2011 01:25:06 +0200 Subject: [PATCH] Moved Guard::Listener#update_last_event inside Guard::Listener#modified_files Since the pattern was to always call Guard::Listener#update_last_event after Guard::Listener#modified_files. --- lib/guard.rb | 3 +-- lib/guard/listener.rb | 5 +++-- lib/guard/listeners/darwin.rb | 5 ++--- lib/guard/listeners/linux.rb | 5 ++--- lib/guard/listeners/polling.rb | 3 +-- lib/guard/listeners/windows.rb | 6 +++--- 6 files changed, 12 insertions(+), 15 deletions(-) diff --git a/lib/guard.rb b/lib/guard.rb index 5cad6bd..a297f12 100644 --- a/lib/guard.rb +++ b/lib/guard.rb @@ -50,8 +50,7 @@ module Guard end # Reparse the whole directory to catch new files modified during the guards run - new_modified_files = listener.modified_files([Dir.pwd + '/'], :all => true) - listener.update_last_event + new_modified_files = listener.modified_files([Dir.pwd], :all => true) if !new_modified_files.empty? && Watcher.match_files?(guards, new_modified_files) run { run_on_change_for_all_guards(new_modified_files) } end diff --git a/lib/guard/listener.rb b/lib/guard/listener.rb index 4b5742a..669f163 100644 --- a/lib/guard/listener.rb +++ b/lib/guard/listener.rb @@ -46,9 +46,10 @@ module Guard @last_event = Time.now end - def modified_files(dirs, options = {}) + def modified_files(dirs, options={}) files = potentially_modified_files(dirs, options).select { |path| file_modified?(path) } - relativate_paths files + update_last_event + relativize_paths(files) end def worker diff --git a/lib/guard/listeners/darwin.rb b/lib/guard/listeners/darwin.rb index 068df43..fac8093 100644 --- a/lib/guard/listeners/darwin.rb +++ b/lib/guard/listeners/darwin.rb @@ -38,10 +38,9 @@ module Guard private def watch(directory) - worker.watch directory do |modified_dirs| + worker.watch(directory) do |modified_dirs| files = modified_files(modified_dirs) - update_last_event - callback.call(files) + @callback.call(files) unless files.empty? end end diff --git a/lib/guard/listeners/linux.rb b/lib/guard/listeners/linux.rb index 35c465a..5622a31 100644 --- a/lib/guard/listeners/linux.rb +++ b/lib/guard/listeners/linux.rb @@ -65,9 +65,8 @@ module Guard sleep latency inotify.process - modified_files = modified_files(files.shift(files.size).map{|f| File.dirname(f) + '/' }.uniq) - update_last_event - callback.call(modified_files) unless modified_files.empty? + files = modified_files(@files.shift(@files.size).map { |f| File.dirname(f) }.uniq) + @callback.call(files) unless files.empty? end end @watch_change = false diff --git a/lib/guard/listeners/polling.rb b/lib/guard/listeners/polling.rb index 2f61a6d..cbaed22 100644 --- a/lib/guard/listeners/polling.rb +++ b/lib/guard/listeners/polling.rb @@ -24,9 +24,8 @@ module Guard until @stop start = Time.now.to_f files = modified_files([Dir.pwd + '/'], :all => true) - update_last_event - callback.call(relativate_paths(files)) unless files.empty? nap_time = latency - (Time.now.to_f - start) + @callback.call(files) unless files.empty? sleep(nap_time) if nap_time > 0 end end diff --git a/lib/guard/listeners/windows.rb b/lib/guard/listeners/windows.rb index 195c492..4f5d6c4 100644 --- a/lib/guard/listeners/windows.rb +++ b/lib/guard/listeners/windows.rb @@ -35,9 +35,9 @@ module Guard def watch(directory) worker.watch(directory, :all_events, :recursive) do |event| paths = [File.expand_path(event.watcher.path) + '/'] - files = modified_files(paths, {:all => true}) - update_last_event - callback.call(files) + paths = [File.expand_path(event.watcher.path)] + files = modified_files(paths, :all => true) + @callback.call(files) unless files.empty? end end