Skip to content

Commit 8e293dd

Browse files
committed
refactor: move directory path logic to InternalConfig
- Add directory name constants (TEMPLATES_DIR_NAME, ANSIBLE_DIR_NAME, TOFU_DIR_NAME) - Move directory path methods from EnvironmentContext to InternalConfig - Update EnvironmentContext methods to delegate to InternalConfig - Improves separation of concerns and maintainability - All directory names now use constants instead of hardcoded strings
1 parent 255f229 commit 8e293dd

File tree

3 files changed

+63
-6
lines changed

3 files changed

+63
-6
lines changed

src/domain/environment/context.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,46 +183,46 @@ impl EnvironmentContext {
183183
/// Path: `data/{env_name}/templates/`
184184
#[must_use]
185185
pub fn templates_dir(&self) -> PathBuf {
186-
self.internal_config.data_dir.join("templates")
186+
self.internal_config.templates_dir()
187187
}
188188

189189
/// Returns the traces directory for this environment
190190
///
191191
/// Path: `data/{env_name}/traces/`
192192
#[must_use]
193193
pub fn traces_dir(&self) -> PathBuf {
194-
self.internal_config.data_dir.join(super::TRACES_DIR_NAME)
194+
self.internal_config.traces_dir()
195195
}
196196

197197
/// Returns the ansible build directory
198198
///
199199
/// Path: `build/{env_name}/ansible`
200200
#[must_use]
201201
pub fn ansible_build_dir(&self) -> PathBuf {
202-
self.internal_config.build_dir.join("ansible")
202+
self.internal_config.ansible_build_dir()
203203
}
204204

205205
/// Returns the tofu build directory
206206
///
207207
/// Path: `build/{env_name}/tofu`
208208
#[must_use]
209209
pub fn tofu_build_dir(&self) -> PathBuf {
210-
self.internal_config.build_dir.join("tofu")
210+
self.internal_config.tofu_build_dir()
211211
}
212212

213213
/// Returns the ansible templates directory
214214
///
215215
/// Path: `data/{env_name}/templates/ansible`
216216
#[must_use]
217217
pub fn ansible_templates_dir(&self) -> PathBuf {
218-
self.templates_dir().join("ansible")
218+
self.internal_config.ansible_templates_dir()
219219
}
220220

221221
/// Returns the tofu templates directory
222222
///
223223
/// Path: `data/{env_name}/templates/tofu`
224224
#[must_use]
225225
pub fn tofu_templates_dir(&self) -> PathBuf {
226-
self.templates_dir().join("tofu")
226+
self.internal_config.tofu_templates_dir()
227227
}
228228
}

src/domain/environment/internal_config.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,52 @@ impl InternalConfig {
8686
data_dir,
8787
}
8888
}
89+
90+
/// Returns the templates directory for this environment
91+
///
92+
/// Path: `data/{env_name}/templates/`
93+
#[must_use]
94+
pub fn templates_dir(&self) -> PathBuf {
95+
self.data_dir.join(super::TEMPLATES_DIR_NAME)
96+
}
97+
98+
/// Returns the traces directory for this environment
99+
///
100+
/// Path: `data/{env_name}/traces/`
101+
#[must_use]
102+
pub fn traces_dir(&self) -> PathBuf {
103+
self.data_dir.join(super::TRACES_DIR_NAME)
104+
}
105+
106+
/// Returns the ansible build directory
107+
///
108+
/// Path: `build/{env_name}/ansible`
109+
#[must_use]
110+
pub fn ansible_build_dir(&self) -> PathBuf {
111+
self.build_dir.join(super::ANSIBLE_DIR_NAME)
112+
}
113+
114+
/// Returns the tofu build directory
115+
///
116+
/// Path: `build/{env_name}/tofu`
117+
#[must_use]
118+
pub fn tofu_build_dir(&self) -> PathBuf {
119+
self.build_dir.join(super::TOFU_DIR_NAME)
120+
}
121+
122+
/// Returns the ansible templates directory
123+
///
124+
/// Path: `data/{env_name}/templates/ansible`
125+
#[must_use]
126+
pub fn ansible_templates_dir(&self) -> PathBuf {
127+
self.templates_dir().join(super::ANSIBLE_DIR_NAME)
128+
}
129+
130+
/// Returns the tofu templates directory
131+
///
132+
/// Path: `data/{env_name}/templates/tofu`
133+
#[must_use]
134+
pub fn tofu_templates_dir(&self) -> PathBuf {
135+
self.templates_dir().join(super::TOFU_DIR_NAME)
136+
}
89137
}

src/domain/environment/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ use std::path::PathBuf;
128128
/// Directory name for trace files within an environment's data directory
129129
pub const TRACES_DIR_NAME: &str = "traces";
130130

131+
/// Directory name for template files within an environment's data directory
132+
pub const TEMPLATES_DIR_NAME: &str = "templates";
133+
134+
/// Directory name for Ansible-related files
135+
pub const ANSIBLE_DIR_NAME: &str = "ansible";
136+
137+
/// Directory name for OpenTofu-related files
138+
pub const TOFU_DIR_NAME: &str = "tofu";
139+
131140
/// Environment configuration encapsulating all environment-specific settings
132141
///
133142
/// This entity represents a complete environment configuration including naming,

0 commit comments

Comments
 (0)