Class: QuietQuality::Config::FileFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/quiet_quality/config/file_filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_stringsObject (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_stringObject (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

#excludesObject



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

Returns:

  • (Boolean)


34
35
36
# File 'lib/quiet_quality/config/file_filter.rb', line 34

def match?(s)
  regex_match?(s) && !excludes_match?(s)
end

#regexObject



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