Class: Ace::Support::Config::Atoms::PathRuleMatcher
- Inherits:
-
Object
- Object
- Ace::Support::Config::Atoms::PathRuleMatcher
- Defined in:
- lib/ace/support/config/atoms/path_rule_matcher.rb
Overview
Match file paths against path-based config rules
Defined Under Namespace
Classes: MatchResult
Instance Method Summary collapse
-
#initialize(path_rules, project_root: nil) ⇒ PathRuleMatcher
constructor
A new instance of PathRuleMatcher.
-
#match(file_path) ⇒ MatchResult?
Match file path against configured rules.
Constructor Details
#initialize(path_rules, project_root: nil) ⇒ PathRuleMatcher
Returns a new instance of PathRuleMatcher.
13 14 15 16 |
# File 'lib/ace/support/config/atoms/path_rule_matcher.rb', line 13 def initialize(path_rules, project_root: nil) @path_rules = path_rules || {} @project_root = project_root end |
Instance Method Details
#match(file_path) ⇒ MatchResult?
Match file path against configured rules
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ace/support/config/atoms/path_rule_matcher.rb', line 21 def match(file_path) return nil if @path_rules.nil? || @path_rules.empty? return nil if file_path.nil? || file_path.to_s.empty? normalized = normalize_path(file_path) @path_rules.each do |name, rule| next unless rule.is_a?(Hash) glob = rule["glob"] || rule[:glob] globs = Array(glob).compact.map(&:to_s).reject(&:empty?) next if globs.empty? # Calculate path relative to rule's config root # Returns nil if file is outside config root's scope path_to_match = path_relative_to_config(normalized, rule) next if path_to_match.nil? globs.each do |glob_pattern| next unless File.fnmatch?(glob_pattern, path_to_match, match_flags(glob_pattern)) return MatchResult.new( name: name.to_s, config: extract_config(rule) ) end end nil end |