From cd55e7d62530f3abebdd98f2f26761e64fbeb729 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 5 Mar 2016 11:37:23 +0100 Subject: [PATCH] Add Aspect building based on configuration --- libimagstore/src/configuration.rs | 4 +- libimagstore/src/store.rs | 66 ++++++++++++++++++++++++------- 2 files changed, 54 insertions(+), 16 deletions(-) diff --git a/libimagstore/src/configuration.rs b/libimagstore/src/configuration.rs index 7a8d44d8..c1d91a05 100644 --- a/libimagstore/src/configuration.rs +++ b/libimagstore/src/configuration.rs @@ -1,7 +1,7 @@ -use config::types::{Config, Value}; +use toml::Value; use hook::position::HookPosition; -pub fn config_is_valid(config: &Config) -> bool { +pub fn config_is_valid(config: &Value) -> bool { unimplemented!() } diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 50f4d83d..7a5667b6 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -133,8 +133,14 @@ pub struct Store { impl Store { /// Create a new Store object - pub fn new(location: PathBuf) -> Result { + pub fn new(location: PathBuf, store_config: &Value) -> Result { use std::fs::create_dir_all; + use configuration::*; + + debug!("Validating Store configuration"); + if !config_is_valid(store_config) { + return Err(StoreError::new(StoreErrorKind::ConfigurationError, None)); + } debug!("Building new Store object"); if !location.exists() { @@ -152,21 +158,53 @@ impl Store { } } - debug!("Store building succeeded"); - Ok(Store { + let pre_read_aspects = get_pre_read_aspect_names(store_config) + .into_iter().map(|n| Aspect::new(n)).collect(); + + let post_read_aspects = get_post_read_aspect_names(store_config) + .into_iter().map(|n| Aspect::new(n)).collect(); + + let pre_create_aspects = get_pre_create_aspect_names(store_config) + .into_iter().map(|n| Aspect::new(n)).collect(); + + let post_create_aspects = get_post_create_aspect_names(store_config) + .into_iter().map(|n| Aspect::new(n)).collect(); + + let pre_retrieve_aspects = get_pre_retrieve_aspect_names(store_config) + .into_iter().map(|n| Aspect::new(n)).collect(); + + let post_retrieve_aspects = get_post_retrieve_aspect_names(store_config) + .into_iter().map(|n| Aspect::new(n)).collect(); + + let pre_update_aspects = get_pre_update_aspect_names(store_config) + .into_iter().map(|n| Aspect::new(n)).collect(); + + let post_update_aspects = get_post_update_aspect_names(store_config) + .into_iter().map(|n| Aspect::new(n)).collect(); + + let pre_delete_aspects = get_pre_delete_aspect_names(store_config) + .into_iter().map(|n| Aspect::new(n)).collect(); + + let post_delete_aspects = get_post_delete_aspect_names(store_config) + .into_iter().map(|n| Aspect::new(n)).collect(); + + let store = Store { location: location, - pre_read_aspects : Arc::new(Mutex::new(vec![])), - post_read_aspects : Arc::new(Mutex::new(vec![])), - pre_create_aspects : Arc::new(Mutex::new(vec![])), - post_create_aspects : Arc::new(Mutex::new(vec![])), - pre_retrieve_aspects : Arc::new(Mutex::new(vec![])), - post_retrieve_aspects : Arc::new(Mutex::new(vec![])), - pre_update_aspects : Arc::new(Mutex::new(vec![])), - post_update_aspects : Arc::new(Mutex::new(vec![])), - pre_delete_aspects : Arc::new(Mutex::new(vec![])), - post_delete_aspects : Arc::new(Mutex::new(vec![])), + pre_read_aspects : Arc::new(Mutex::new(pre_read_aspects)), + post_read_aspects : Arc::new(Mutex::new(post_read_aspects)), + pre_create_aspects : Arc::new(Mutex::new(pre_create_aspects)), + post_create_aspects : Arc::new(Mutex::new(post_create_aspects)), + pre_retrieve_aspects : Arc::new(Mutex::new(pre_retrieve_aspects)), + post_retrieve_aspects : Arc::new(Mutex::new(post_retrieve_aspects)), + pre_update_aspects : Arc::new(Mutex::new(pre_update_aspects)), + post_update_aspects : Arc::new(Mutex::new(post_update_aspects)), + pre_delete_aspects : Arc::new(Mutex::new(pre_delete_aspects)), + post_delete_aspects : Arc::new(Mutex::new(post_delete_aspects)), entries: Arc::new(RwLock::new(HashMap::new())), - }) + }; + + debug!("Store building succeeded"); + Ok(store) } fn storify_id(&self, id: StoreId) -> StoreId {