Class: Guard::Watcher::Pattern::DeprecatedRegexp
- Inherits:
-
Object
- Object
- Guard::Watcher::Pattern::DeprecatedRegexp
- Defined in:
- lib/guard/watcher/pattern/deprecated_regexp.rb
Overview
TODO: remove before Guard 3.x
Class Method Summary collapse
Instance Method Summary collapse
- #deprecated? ⇒ Boolean
-
#initialize(pattern) ⇒ DeprecatedRegexp
constructor
A new instance of DeprecatedRegexp.
Constructor Details
#initialize(pattern) ⇒ DeprecatedRegexp
Returns a new instance of DeprecatedRegexp.
8 9 10 |
# File 'lib/guard/watcher/pattern/deprecated_regexp.rb', line 8 def initialize(pattern) @original_pattern = pattern end |
Class Method Details
.convert(pattern) ⇒ Object
12 13 14 |
# File 'lib/guard/watcher/pattern/deprecated_regexp.rb', line 12 def self.convert(pattern) Matcher.new(Regexp.new(pattern)) end |
.show_deprecation(pattern) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/guard/watcher/pattern/deprecated_regexp.rb', line 21 def self.show_deprecation(pattern) @warning_printed ||= false unless @warning_printed msg = "*" * 20 + "\nDEPRECATION WARNING!\n" + "*" * 20 msg += <<-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 UI.deprecation(msg) @warning_printed = true end new_regexp = Regexp.new(pattern).inspect UI.info "\"#{pattern}\" will be converted to #{new_regexp}\n" end |
Instance Method Details
#deprecated? ⇒ Boolean
16 17 18 19 |
# File 'lib/guard/watcher/pattern/deprecated_regexp.rb', line 16 def deprecated? regexp = /(^(\^))|(>?(\\\.)|(\.\*))|(\(.*\))|(\[.*\])|(\$$)/ @original_pattern.is_a?(String) && regexp.match(@original_pattern) end |