Class: QuietQuality::Config::FileFilter
- Inherits:
-
Object
- Object
- QuietQuality::Config::FileFilter
- Defined in:
- lib/quiet_quality/config/file_filter.rb
Instance Attribute Summary collapse
-
#excludes_strings ⇒ Object
readonly
Returns the value of attribute excludes_strings.
-
#regex_string ⇒ Object
readonly
Returns the value of attribute regex_string.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #excludes ⇒ Object
-
#initialize(regex: nil, excludes: nil) ⇒ FileFilter
constructor
-
regex is a regex string * excludes is an array of regex strings OR a single regex string.
-
-
#match?(s) ⇒ Boolean
The filter overall matches if: (a) the regex either matches or is not supplied AND (b) either none of the excludes match or none are supplied.
- #regex ⇒ Object
Constructor Details
#initialize(regex: nil, excludes: nil) ⇒ FileFilter
-
regex is a regex string
-
excludes is an array of regex strings OR a single regex string
6 7 8 9 |
# File 'lib/quiet_quality/config/file_filter.rb', line 6 def initialize(regex: nil, excludes: nil) @regex_string = regex @excludes_strings = excludes end |
Instance Attribute Details
#excludes_strings ⇒ Object (readonly)
Returns the value of attribute excludes_strings.
11 12 13 |
# File 'lib/quiet_quality/config/file_filter.rb', line 11 def excludes_strings @excludes_strings end |
#regex_string ⇒ Object (readonly)
Returns the value of attribute regex_string.
11 12 13 |
# File 'lib/quiet_quality/config/file_filter.rb', line 11 def regex_string @regex_string end |
Instance Method Details
#==(other) ⇒ Object
38 39 40 |
# File 'lib/quiet_quality/config/file_filter.rb', line 38 def ==(other) regex_string == other.regex_string && excludes_strings.sort == other.excludes_strings.sort end |
#excludes ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/quiet_quality/config/file_filter.rb', line 18 def excludes return @_excludes if defined?(@_excludes) @_excludes = if @excludes_strings.nil? nil elsif @excludes_strings.is_a?(String) [Regexp.new(@excludes_strings)] else @excludes_strings.map { |xs| Regexp.new(xs) } end end |
#match?(s) ⇒ Boolean
The filter overall matches if: (a) the regex either matches or is not supplied AND (b) either none of the excludes match or none are supplied
34 35 36 |
# File 'lib/quiet_quality/config/file_filter.rb', line 34 def match?(s) regex_match?(s) && !excludes_match?(s) end |
#regex ⇒ Object
13 14 15 16 |
# File 'lib/quiet_quality/config/file_filter.rb', line 13 def regex return nil if @regex_string.nil? @_regex ||= Regexp.new(@regex_string) end |