Class: PathList::RuleGroup
- Inherits:
-
Object
- Object
- PathList::RuleGroup
- Defined in:
- lib/path_list/rule_group.rb
Direct Known Subclasses
Instance Method Summary collapse
- #allowed_recursive?(root_candidate) ⇒ Boolean
- #allowed_unrecursive?(root_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/path_list/rule_group.rb', line 5 def initialize(patterns, allow) @matchers = Array(patterns).flat_map { |x| x.build_matchers(include: allow) }.compact @allow = allow @allowed_recursive = { '/' => true } end |
Instance Method Details
#allowed_recursive?(root_candidate) ⇒ Boolean
25 26 27 28 29 30 31 |
# File 'lib/path_list/rule_group.rb', line 25 def allowed_recursive?(root_candidate) @allowed_recursive.fetch(root_candidate.full_path) do @allowed_recursive[root_candidate.full_path] = allowed_recursive?(root_candidate.parent) && allowed_unrecursive?(root_candidate) end end |
#allowed_unrecursive?(root_candidate) ⇒ Boolean
33 34 35 36 37 38 39 40 |
# File 'lib/path_list/rule_group.rb', line 33 def allowed_unrecursive?(root_candidate) @matchers.reverse_each do |matcher| val = matcher.match?(root_candidate) return val == :allow if val end not @allow end |
#empty? ⇒ Boolean
11 12 13 |
# File 'lib/path_list/rule_group.rb', line 11 def empty? @matchers.empty? || @matchers.all?(&:empty?) end |
#freeze ⇒ Object
19 20 21 22 23 |
# File 'lib/path_list/rule_group.rb', line 19 def freeze @matchers.freeze super end |
#weight ⇒ Object
15 16 17 |
# File 'lib/path_list/rule_group.rb', line 15 def weight @matchers.sum(&:weight) end |