use std::path::PathBuf;
use crate::config::Config;
#[derive(Clone, Debug)]
pub(crate) struct ConfigRepository {
path: Option<PathBuf>,
}
impl ConfigRepository {
pub(crate) fn new(path: Option<PathBuf>) -> Self {
Self { path }
}
pub(crate) fn load(&self) -> anyhow::Result<Config> {
Config::load(self.path.clone())
}
pub(crate) fn save(&self, config: &Config) -> anyhow::Result<()> {
config.save(self.path.clone())
}
pub(crate) fn update<T>(&self, update: impl FnOnce(&mut Config) -> T) -> anyhow::Result<T> {
let mut config = self.load()?;
let value = update(&mut config);
self.save(&config)?;
Ok(value)
}
}
#[cfg(test)]
#[path = "config_repository_tests.rs"]
mod tests;