class Guard::Watcher
def initialize(pattern, action = nil)
-
action(Block) -- the action to execute before passing the result to -
pattern(String, Regexp) -- the pattern to be watched by the Guard
def initialize(pattern, action = nil) @pattern, @action = pattern, action @@warning_printed ||= false # deprecation warning regexp = /(^(\^))|(>?(\\\.)|(\.\*))|(\(.*\))|(\[.*\])|(\$$)/ return unless @pattern.is_a?(String) && @pattern =~ regexp unless @@warning_printed UI.info "*" * 20 + "\nDEPRECATION WARNING!\n" + "*" * 20 UI.info <<-MSG You have a string in your Guardfile watch patterns that seem to represent a Regexp. Guard matches String with == and Regexp with Regexp#match. You should either use plain String (without Regexp special characters) or real Regexp. MSG @@warning_printed = true end new_regexp = Regexp.new(@pattern).inspect UI.info "\"#{@pattern}\" has been converted to #{ new_regexp }\n" @pattern = Regexp.new(@pattern) end