feat(config): add method to list all configs

This commit is contained in:
Federico Terzi 2021-04-10 12:04:53 +02:00
parent 3ecc4e8546
commit 14fdfe4149
2 changed files with 13 additions and 4 deletions

View File

@ -39,6 +39,7 @@ pub trait Config {
pub trait ConfigStore { pub trait ConfigStore {
fn default(&self) -> &dyn Config; fn default(&self) -> &dyn Config;
fn active<'a>(&'a self, app: &AppProperties) -> &'a dyn Config; fn active<'a>(&'a self, app: &AppProperties) -> &'a dyn Config;
fn configs(&self) -> Vec<&dyn Config>;
fn get_all_match_paths(&self) -> HashSet<String>; fn get_all_match_paths(&self) -> HashSet<String>;
} }

View File

@ -42,6 +42,17 @@ impl ConfigStore for DefaultConfigStore {
self.default.as_ref() self.default.as_ref()
} }
fn configs(&self) -> Vec<&dyn Config> {
let mut configs = Vec::new();
configs.push(self.default.as_ref());
for custom in self.customs.iter() {
configs.push(custom.as_ref());
}
configs
}
// TODO: test // TODO: test
fn get_all_match_paths(&self) -> HashSet<String> { fn get_all_match_paths(&self) -> HashSet<String> {
let mut paths = HashSet::new(); let mut paths = HashSet::new();
@ -108,10 +119,7 @@ impl DefaultConfigStore {
} }
pub fn from_configs(default: Box<dyn Config>, customs: Vec<Box<dyn Config>>) -> Result<Self> { pub fn from_configs(default: Box<dyn Config>, customs: Vec<Box<dyn Config>>) -> Result<Self> {
Ok(Self { Ok(Self { default, customs })
default,
customs,
})
} }
} }