use super::{Context, Invariant, Outcome};
pub struct Registry {
rules: Vec<Box<dyn Invariant>>,
}
impl Registry {
pub fn empty() -> Self {
Self { rules: Vec::new() }
}
pub fn from_rules(rules: Vec<Box<dyn Invariant>>) -> Self {
Self { rules }
}
pub fn builtin() -> Self {
use super::rules::*;
Self::from_rules(vec![
Box::new(no_unsafe::NoUnsafe),
Box::new(file_size_le_1000::FileSizeLe1000),
Box::new(workspace_edition_pinned::WorkspaceEditionPinned),
Box::new(no_wildcard::NoWildcardDep),
Box::new(readme_exists::ReadmeExists),
Box::new(license_declared::LicenseDeclared),
Box::new(claude_md_exists::ClaudeMdExists),
Box::new(todo_count::TodoCount),
Box::new(no_aws_key_pattern::NoAwsKeyPattern),
Box::new(no_hardcoded_url::NoHardcodedUrl),
Box::new(adr_frontmatter_valid::AdrFrontmatterValid),
Box::new(dep_direction::DepDirection),
Box::new(adr_not_deleted::AdrNotDeleted),
Box::new(feature_frontmatter::FeatureFrontmatterValid),
Box::new(crate_tested::CrateTested),
Box::new(no_aliases::NoAliases),
Box::new(side_effect_boundary::SideEffectBoundary),
])
}
pub fn rules(&self) -> impl Iterator<Item = &dyn Invariant> {
self.rules.iter().map(|r| r.as_ref())
}
pub fn len(&self) -> usize {
self.rules.len()
}
pub fn is_empty(&self) -> bool {
self.rules.is_empty()
}
pub fn find(&self, id: &str) -> Option<&dyn Invariant> {
self.rules.iter().map(|r| r.as_ref()).find(|r| r.id() == id)
}
pub fn evaluate_all(&self, ctx: &Context) -> Vec<(&'static str, Outcome)> {
self.rules
.iter()
.map(|r| (r.id(), r.evaluate(ctx)))
.collect()
}
}