class FastIgnore::RuleSet
Attributes
dir_rules[R]
file_rules[R]
gitignore[R]
gitignore?[R]
has_shebang_rules[R]
Public Class Methods
new(rules, allow, gitignore, squash = true)
click to toggle source
# File lib/fast_ignore/rule_set.rb, line 9 def initialize(rules, allow, gitignore, squash = true) @dir_rules = (squash ? squash_rules(rules.reject(&:file_only?)) : rules.reject(&:file_only?)).freeze @file_rules = (squash ? squash_rules(rules.reject(&:dir_only?)) : rules.reject(&:dir_only?)).freeze @has_shebang_rules = rules.any?(&:shebang?) @allowed_recursive = { '.' => true } @allow = allow @gitignore = gitignore freeze unless gitignore? end
Public Instance Methods
<<(other)
click to toggle source
# File lib/fast_ignore/rule_set.rb, line 21 def <<(other) return unless other @has_shebang_rules ||= other.has_shebang_rules @dir_rules = squash_rules(@dir_rules + other.dir_rules) @file_rules = squash_rules(@file_rules + other.file_rules) end
allowed_recursive?(relative_path, dir, full_path, filename, content = nil)
click to toggle source
# File lib/fast_ignore/rule_set.rb, line 29 def allowed_recursive?(relative_path, dir, full_path, filename, content = nil) @allowed_recursive.fetch(relative_path) do @allowed_recursive[relative_path] = allowed_recursive?(::File.dirname(relative_path), true, nil, nil, nil) && allowed_unrecursive?(relative_path, dir, full_path, filename, content) end end
allowed_unrecursive?(relative_path, dir, full_path, filename, content)
click to toggle source
# File lib/fast_ignore/rule_set.rb, line 37 def allowed_unrecursive?(relative_path, dir, full_path, filename, content) (dir ? @dir_rules : @file_rules).reverse_each do |rule| return rule.negation? if rule.match?(relative_path, full_path, filename, content) end not @allow end
empty?()
click to toggle source
# File lib/fast_ignore/rule_set.rb, line 66 def empty? @dir_rules.empty? && @file_rules.empty? end
squash_rules(rules)
click to toggle source
# File lib/fast_ignore/rule_set.rb, line 45 def squash_rules(rules) # rubocop:disable Metrics/MethodLength running_component_rule_size = rules.first&.component_rules_count || 0 rules.chunk_while do |a, b| # a.squashable_type == b.squashable_type next true if a.squashable_type == b.squashable_type && (running_component_rule_size + b.component_rules_count <= 40) running_component_rule_size = b.component_rules_count false end.map do |chunk| # rubocop:disable Style/MultilineBlockChain first = chunk.first next first if chunk.length == 1 first.squash(chunk) end end
weight()
click to toggle source
# File lib/fast_ignore/rule_set.rb, line 62 def weight @dir_rules.length + (@has_shebang_rules ? 10 : 0) end