Class: RuboCop::FilePatterns Private

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/file_patterns.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A wrapper around patterns array to perform optimized search.

For projects with a large set of rubocop todo files, most items in ‘Exclude`/`Include` are exact file names. It is wasteful to linearly check the list of patterns over and over to check if the file is relevant to the cop.

This class partitions an array of patterns into a set of exact match strings and the rest of the patterns. This way we can firstly do a cheap check in the set and then proceed via the costly patterns check, if needed.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(patterns) ⇒ FilePatterns

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of FilePatterns.



21
22
23
24
25
# File 'lib/rubocop/file_patterns.rb', line 21

def initialize(patterns)
  @strings = Set.new
  @patterns = []
  partition_patterns(patterns)
end

Class Method Details

.from(patterns) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



17
18
19
# File 'lib/rubocop/file_patterns.rb', line 17

def self.from(patterns)
  @cache[patterns] ||= new(patterns)
end

Instance Method Details

#match?(path) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


27
28
29
# File 'lib/rubocop/file_patterns.rb', line 27

def match?(path)
  @strings.include?(path) || @patterns.any? { |pattern| PathUtil.match_path?(pattern, path) }
end