class FastIgnore::Rule

Attributes

component_rules[R]
component_rules_count[R]
dir_only[R]
dir_only?[R]
negation[R]
negation?[R]
rule[R]
squashable_type[R]

Public Class Methods

new(rule, negation, anchored, dir_only, component_rules = self) click to toggle source
# File lib/fast_ignore/rule.rb, line 28
def initialize(rule, negation, anchored, dir_only, component_rules = self) # rubocop:disable Metrics/MethodLength
  @rule = rule
  @anchored = anchored
  @dir_only = dir_only
  @negation = negation
  @component_rules = component_rules
  @component_rules_count = component_rules == self ? 1 : component_rules.length

  @squashable_type = if anchored && negation
    1
  elsif anchored
    0
  else
    ::Float::NAN # because it doesn't equal itself
  end

  freeze
end

Public Instance Methods

file_only?() click to toggle source
# File lib/fast_ignore/rule.rb, line 47
def file_only?
  false
end
inspect() click to toggle source

:nocov:

# File lib/fast_ignore/rule.rb, line 56
def inspect
  "#<Rule #{'!' if @negation}#{'/' if @anchored}#{@rule}#{'/' if @dir_only}>"
end
match?(relative_path, _full_path, _filename, _content) click to toggle source

:nocov:

# File lib/fast_ignore/rule.rb, line 61
def match?(relative_path, _full_path, _filename, _content)
  @rule.match?(relative_path)
end
shebang?() click to toggle source
# File lib/fast_ignore/rule.rb, line 51
def shebang?
  false
end
squash(rules) click to toggle source
# File lib/fast_ignore/rule.rb, line 19
def squash(rules)
  # component rules is to improve the performance of repos with many .gitignore files. e.g. linux.
  component_rules = rules.flat_map(&:component_rules)
  ::FastIgnore::Rule.new(
    ::Regexp.union(component_rules.map(&:rule)).freeze,
    @negation, @anchored, @dir_only, component_rules
  )
end