From b2f282f1e80576bc6bde74b95acd2310f3c1f7ea Mon Sep 17 00:00:00 2001 From: Kevin Krauss Date: Sun, 9 Oct 2011 15:54:24 -0700 Subject: [PATCH] watcher cleaned up. --- lib/guard/watcher.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/guard/watcher.rb b/lib/guard/watcher.rb index 9391d10..263ec67 100644 --- a/lib/guard/watcher.rb +++ b/lib/guard/watcher.rb @@ -6,15 +6,16 @@ module Guard # class Watcher - attr_accessor :pattern, :action, :any_rtn + attr_accessor :pattern, :action, :any_return # Initialize a file watcher. # # @param [String, Regexp] pattern the pattern to be watched by the guard # @param [Block] action the action to execute before passing the result to the Guard + # @param [Boolean] any_return allow the user to define return when using a block # - def initialize(pattern, action = nil, any_rtn = false) - @pattern, @action, @any_rtn = pattern, action, any_rtn + def initialize(pattern, action = nil, any_return = false) + @pattern, @action, @any_return = pattern, action, any_return @@warning_printed ||= false # deprecation warning @@ -41,12 +42,11 @@ module Guard # @return [Array] the matched watcher response def self.match_files(guard, files) guard.watchers.inject([]) do |paths, watcher| - wa = watcher.any_rtn files.each do |file| if matches = watcher.match_file?(file) if watcher.action result = watcher.call_action(matches) - if wa + if watcher.any_return paths << result elsif result.respond_to?(:empty?) && ! result.empty? paths << Array(result) @@ -57,7 +57,7 @@ module Guard end end - wa ? paths : paths.flatten.map{|p| p.to_s} + watcher.any_return ? paths : paths.flatten.map{|p| p.to_s} end end