Store: Add hook configuration on registration
This commit is contained in:
parent
59fdb7ef3d
commit
0286d8a25e
1 changed files with 18 additions and 1 deletions
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue