Store: Add hook configuration on registration

This commit is contained in:
Matthias Beyer 2016-03-05 18:10:38 +01:00
parent 59fdb7ef3d
commit 0286d8a25e

View file

@ -375,7 +375,7 @@ impl Store {
pub fn register_hook(&mut self, pub fn register_hook(&mut self,
position: HookPosition, position: HookPosition,
aspect_name: &String, aspect_name: &String,
h: Box<Hook>) mut h: Box<Hook>)
-> Result<()> -> Result<()>
{ {
debug!("Registering hook: {:?}", h); debug!("Registering hook: {:?}", h);
@ -407,6 +407,7 @@ impl Store {
let mut guard = guard.unwrap(); let mut guard = guard.unwrap();
for mut aspect in guard.deref_mut() { for mut aspect in guard.deref_mut() {
if aspect.name().clone() == aspect_name.clone() { if aspect.name().clone() == aspect_name.clone() {
self.get_config_for_hook(h.name()).map(|config| h.set_config(config));
aspect.register_hook(h); aspect.register_hook(h);
return Ok(()); return Ok(());
} }
@ -414,6 +415,22 @@ impl Store {
return Err(StoreError::new(StoreErrorKind::HookRegisterError, None)); return Err(StoreError::new(StoreErrorKind::HookRegisterError, None));
} }
fn get_config_for_hook(&self, name: &str) -> Option<&Value> {
match &self.configuration {
&Value::Table(ref tabl) => {
tabl.get("hooks")
.map(|hook_section| {
match hook_section {
&Value::Table(ref tabl) => tabl.get(name),
_ => None
}
})
.unwrap_or(None)
},
_ => None,
}
}
fn execute_hooks_for_id(&self, fn execute_hooks_for_id(&self,
aspects: Arc<Mutex<Vec<Aspect>>>, aspects: Arc<Mutex<Vec<Aspect>>>,
id: &StoreId) id: &StoreId)