2010-10-03 21:00:33 +00:00
|
|
|
module Guard
|
|
|
|
class Watcher
|
|
|
|
attr_accessor :pattern, :action
|
|
|
|
|
|
|
|
def initialize(pattern, action = nil)
|
|
|
|
@pattern, @action = pattern, action
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.match_files(guard, files)
|
|
|
|
guard.watchers.inject([]) do |paths, watcher|
|
|
|
|
files.each do |file|
|
|
|
|
if matches = file.match(watcher.pattern)
|
|
|
|
if watcher.action
|
|
|
|
begin
|
2010-10-07 20:37:13 +00:00
|
|
|
if watcher.action.arity == 1
|
2010-10-03 21:00:33 +00:00
|
|
|
result = watcher.action.call(matches)
|
2010-10-07 20:37:13 +00:00
|
|
|
else
|
|
|
|
result = watcher.action.call
|
2010-10-03 21:00:33 +00:00
|
|
|
end
|
|
|
|
rescue
|
|
|
|
UI.info "Problem with watch action"
|
|
|
|
end
|
|
|
|
paths << result if result.is_a?(String) && result != ''
|
|
|
|
else
|
|
|
|
paths << matches[0]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
paths
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|