master/lib/guard/watcher.rb

34 lines
878 B
Ruby
Raw Normal View History

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
if watcher.action.arity == 1
2010-10-03 21:00:33 +00:00
result = watcher.action.call(matches)
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