When using a block allow none string return

This commit is contained in:
Kevin Krauss 2011-10-04 22:17:07 -07:00
parent 3c75205dd0
commit 47f3d878f6

View File

@ -39,21 +39,20 @@ module Guard
# @param [Guard::Guard] guard the guard which watchers are used # @param [Guard::Guard] guard the guard which watchers are used
# @param [Array<String>] files the changed files # @param [Array<String>] files the changed files
# @return [Array<String>] the matched files # @return [Array<String>] the matched files
# # @optional_return [Anything] return whatever you want to path
def self.match_files(guard, files) def self.match_files(guard, files)
guard.watchers.inject([]) do |paths, watcher| guard.watchers.inject([]) do |paths, watcher|
files.each do |file| files.each do |file|
if matches = watcher.match_file?(file) if matches = watcher.match_file?(file)
if watcher.action if watcher.action
result = watcher.call_action(matches) result = watcher.call_action(matches)
paths << Array(result) if result.respond_to?(:empty?) && !result.empty? paths << Array(result) if result
else else
paths << matches[0] paths << matches[0]
end end
end end
end end
return paths
paths.flatten.map { |p| p.to_s }
end end
end end