1#[cfg(test)]
4mod tests;
5
6use std::path::{Path, PathBuf};
7
8use crate::MealPlannerError;
9
10#[derive(Debug, Clone, PartialEq, Eq)]
12pub struct MealPlannerConfig {
13 database_path: PathBuf,
14}
15
16impl MealPlannerConfig {
17 pub fn from_data_dir(data_dir: impl AsRef<Path>) -> Self {
19 Self {
20 database_path: data_dir.as_ref().join("meal-planner.sqlite"),
21 }
22 }
23
24 pub fn new(database_path: impl Into<PathBuf>) -> Result<Self, MealPlannerError> {
26 let database_path = database_path.into();
27 if database_path.as_os_str().is_empty() {
28 return Err(MealPlannerError::InvalidConfiguration(
29 "database path must not be empty".into(),
30 ));
31 }
32 Ok(Self { database_path })
33 }
34
35 pub fn database_path(&self) -> &Path {
37 &self.database_path
38 }
39}