Class: FastIgnore::RuleGroup
- Inherits:
-
Object
- Object
- FastIgnore::RuleGroup
- Defined in:
- lib/fast_ignore/rule_group.rb
Direct Known Subclasses
Instance Method Summary collapse
- #allowed_recursive?(candidate) ⇒ Boolean
- #allowed_unrecursive?(candidate) ⇒ Boolean
- #empty? ⇒ Boolean
- #freeze ⇒ Object
-
#initialize(patterns, allow) ⇒ RuleGroup
constructor
A new instance of RuleGroup.
- #weight ⇒ Object
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
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
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
11 12 13 |
# File 'lib/fast_ignore/rule_group.rb', line 11 def empty? @matchers.empty? || @matchers.all?(&:empty?) end |
#freeze ⇒ Object
19 20 21 22 23 |
# File 'lib/fast_ignore/rule_group.rb', line 19 def freeze @matchers.freeze super end |
#weight ⇒ Object
15 16 17 |
# File 'lib/fast_ignore/rule_group.rb', line 15 def weight @matchers.sum(&:weight) end |