use super::{CompiledGroup, CompiledPolicy};
use crate::kind::Kind;
use crate::pattern::GlobPattern;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum Section {
Deny,
RepoReview,
Allow,
Review,
Defer,
}
impl Section {
pub(crate) const ALL: [Self; 5] = [
Self::Deny,
Self::RepoReview,
Self::Allow,
Self::Review,
Self::Defer,
];
}
impl CompiledPolicy<'_> {
pub(crate) fn section(&self, section: Section) -> &[CompiledGroup] {
match section {
Section::Deny => &self.deny,
Section::RepoReview => &self.repo_review,
Section::Allow => &self.allow,
Section::Review => &self.review,
Section::Defer => &self.defer,
}
}
}
impl CompiledGroup {
pub(crate) fn id(&self) -> &str {
&self.id
}
pub(crate) fn globs(&self, kind: Kind) -> &[GlobPattern] {
&self.globs[kind as usize]
}
pub(crate) fn bare_globs(&self, kind: Kind) -> Option<&[GlobPattern]> {
self.bare_hosts
.as_ref()
.map(|b| b[kind as usize].as_slice())
}
pub(crate) fn conditional(&self) -> bool {
self.when.is_some()
}
}