Class: FastIgnore::RuleGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/fast_ignore/rule_group.rb

Direct Known Subclasses

GitignoreRuleGroup

Instance Method Summary collapse

Constructor Details

#initialize(patterns, allow) ⇒ RuleGroup

Returns a new instance of RuleGroup.



5
6
7
8
9
# File 'lib/fast_ignore/rule_group.rb', line 5

def initialize(patterns, allow)
  @matchers = Array(patterns).flat_map { |x| x.build_matchers(allow: allow) }.compact
  @allow = allow
  @allowed_recursive = { ::FastIgnore::Candidate.root.key => true }.compare_by_identity
end

Instance Method Details

#allowed_recursive?(candidate) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
# File 'lib/fast_ignore/rule_group.rb', line 25

def allowed_recursive?(candidate)
  @allowed_recursive.fetch(candidate.key) do
    @allowed_recursive[candidate.key] =
      allowed_recursive?(candidate.parent) &&
      allowed_unrecursive?(candidate)
  end
end

#allowed_unrecursive?(candidate) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
# File 'lib/fast_ignore/rule_group.rb', line 33

def allowed_unrecursive?(candidate)
  @matchers.reverse_each do |matcher|
    val = matcher.match?(candidate)
    return val == :allow if val
  end

  not @allow
end

#empty?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/fast_ignore/rule_group.rb', line 11

def empty?
  @matchers.empty? || @matchers.all?(&:empty?)
end

#freezeObject



19
20
21
22
23
# File 'lib/fast_ignore/rule_group.rb', line 19

def freeze
  @matchers.freeze

  super
end

#weightObject



15
16
17
# File 'lib/fast_ignore/rule_group.rb', line 15

def weight
  @matchers.sum(&:weight)
end