use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum ScanAction {
#[default]
Allow,
Block,
}
#[derive(Clone, Debug, Default)]
pub struct ScanPolicy {
default: ScanAction,
bundles: BTreeMap<PathBuf, ScanAction>,
audio_units: BTreeMap<String, ScanAction>,
}
impl ScanPolicy {
#[must_use]
pub fn new(default: ScanAction) -> Self {
Self {
default,
..Self::default()
}
}
#[must_use]
pub fn bundle(mut self, path: impl Into<PathBuf>, action: ScanAction) -> Self {
self.bundles.insert(path.into(), action);
self
}
#[must_use]
pub fn audio_unit(mut self, class_id: impl Into<String>, action: ScanAction) -> Self {
self.audio_units
.insert(class_id.into().to_ascii_uppercase(), action);
self
}
pub(super) fn allows_bundle(&self, path: &Path) -> bool {
self.bundles.get(path).copied().unwrap_or(self.default) == ScanAction::Allow
}
pub(super) fn allows_audio_unit(&self, class_id: &str) -> bool {
self.audio_units
.get(&class_id.to_ascii_uppercase())
.copied()
.unwrap_or(self.default)
== ScanAction::Allow
}
}