Class: SwarmSDK::Permissions::PathMatcher
- Inherits:
-
Object
- Object
- SwarmSDK::Permissions::PathMatcher
- Defined in:
- lib/swarm_sdk/permissions/path_matcher.rb
Overview
PathMatcher handles glob pattern matching for file paths
Supports gitignore-style glob patterns with:
- Standard globs: *, **, ?, [abc], a,b
- Recursive matching: */ matches all nested files
- Negation: !pattern to explicitly deny
Examples:
PathMatcher.matches?("tmp/**/*", "tmp/foo/bar.rb") # => true
PathMatcher.matches?("*.log", "debug.log") # => true
PathMatcher.matches?("src/**/*.{rb,js}", "src/a/b.rb") # => true
Class Method Summary collapse
-
.matches?(pattern, path) ⇒ Boolean
Check if a path matches a glob pattern.
Class Method Details
.matches?(pattern, path) ⇒ Boolean
Check if a path matches a glob pattern
23 24 25 26 27 28 29 30 31 |
# File 'lib/swarm_sdk/permissions/path_matcher.rb', line 23 def matches?(pattern, path) # Remove leading ! for negation patterns (handled by caller) pattern = pattern.delete_prefix("!") # Use File.fnmatch with pathname and extglob flags # FNM_PATHNAME: ** matches directories recursively # FNM_EXTGLOB: Support {a,b} patterns File.fnmatch(pattern, path, File::FNM_PATHNAME | File::FNM_EXTGLOB) end |