Skip to main content

ggen_core/codegen/
lifecycle_hooks.rs

1use std::collections::BTreeMap;
2
3/// Phase configuration structure for sync lifecycle
4#[derive(Debug, Clone)]
5pub struct Phase {
6    pub name: String,
7    pub hooks: Option<Vec<String>>,
8}
9
10pub struct SyncLifecycleHooks {
11    phases: BTreeMap<String, Phase>,
12}
13
14impl SyncLifecycleHooks {
15    /// Create new lifecycle hooks manager
16    pub fn new() -> Self {
17        Self {
18            phases: BTreeMap::new(),
19        }
20    }
21
22    /// Register a phase with its hooks
23    pub fn register_phase(&mut self, phase_name: String, hooks: Vec<String>) {
24        self.phases.insert(
25            phase_name.clone(),
26            Phase {
27                name: phase_name,
28                hooks: if hooks.is_empty() { None } else { Some(hooks) },
29            },
30        );
31    }
32
33    /// Get hooks for a specific phase
34    pub fn get_phase_hooks(&self, phase_name: &str) -> Option<Vec<String>> {
35        self.phases.get(phase_name).and_then(|p| p.hooks.clone())
36    }
37
38    /// Check if a phase exists
39    pub fn has_phase(&self, phase_name: &str) -> bool {
40        self.phases.contains_key(phase_name)
41    }
42}
43
44impl Default for SyncLifecycleHooks {
45    fn default() -> Self {
46        Self::new()
47    }
48}
49
50pub struct SyncPhaseConfig {
51    pub before_sync: Vec<String>,
52    pub after_sync: Vec<String>,
53    pub before_generation: Vec<String>,
54    pub after_generation: Vec<String>,
55    pub parallel_rules: bool,
56    pub max_parallelism: Option<usize>,
57}
58
59impl Default for SyncPhaseConfig {
60    fn default() -> Self {
61        Self {
62            before_sync: vec![],
63            after_sync: vec![],
64            before_generation: vec![],
65            after_generation: vec![],
66            parallel_rules: true,
67            max_parallelism: None,
68        }
69    }
70}