use camino::Utf8Path;
use dictator_decree_abi::BoxDecree;
const SHADOWERS: [&str; 6] = ["ruby", "typescript", "golang", "rust", "python", "freebsd"];
pub fn decree_matches(path: &Utf8Path, meta: &dictator_decree_abi::DecreeMetadata) -> bool {
let filename = path.file_name().unwrap_or("");
if meta.supported_extensions.is_empty() && meta.supported_filenames.is_empty() {
return true;
}
if meta.supported_filenames.iter().any(|s| s == filename) {
return true;
}
extension_matches(path, &meta.supported_extensions)
}
pub fn extension_matches(path: &Utf8Path, supported: &[String]) -> bool {
path.extension()
.is_some_and(|ext| supported.iter().any(|s| s == ext))
}
pub fn is_supreme_shadowed(decrees: &[BoxDecree], path: &Utf8Path) -> bool {
decrees.iter().any(|decree| {
let name = decree.name();
if !SHADOWERS.contains(&name) {
return false;
}
let meta = decree.metadata();
decree_matches(path, &meta)
})
}
#[cfg(test)]
mod tests;