Class: BoxtRubyStyleGuide::FilepathMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/boxt_ruby_style_guide/filepath_matcher.rb

Overview

Sanitizes a list of filepaths based on Rubocops exclusions

Constant Summary collapse

FILEPATH_PATTERN_MATCH =

Compare a given filepath with a grep-style filename pattern

proc do |filepath, pattern|
  File.fnmatch(pattern, filepath, File::FNM_PATHNAME)
end
INCLUDE_PATTERNS =

Array of file patterns to make sure we only check files that are Ruby files

%w[
  Gemfile
  Rakefile
  *.gemspec
  **/*.rb
  **/*.rake
].freeze
EXCLUDE_PATTERNS =

Array of the excluded files from Rubocop default.yml config

YAML.load_file(
  BoxtRubyStyleGuide.root.join("default.yml")
).dig("AllCops", "Exclude")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*filepaths) ⇒ FilepathMatcher

Returns a new instance of FilepathMatcher.



33
34
35
# File 'lib/boxt_ruby_style_guide/filepath_matcher.rb', line 33

def initialize(*filepaths)
  @filepaths = filepaths
end

Instance Attribute Details

#filepathsObject (readonly)

Returns the value of attribute filepaths.



31
32
33
# File 'lib/boxt_ruby_style_guide/filepath_matcher.rb', line 31

def filepaths
  @filepaths
end

Instance Method Details

#all_matchesObject



37
38
39
40
41
42
# File 'lib/boxt_ruby_style_guide/filepath_matcher.rb', line 37

def all_matches
  filepaths.select do |filepath|
    filepath_proc = FILEPATH_PATTERN_MATCH.curry.call(filepath)
    INCLUDE_PATTERNS.any?(filepath_proc) && EXCLUDE_PATTERNS.none?(filepath_proc)
  end
end