Skip to content

Commit f7e342a

Browse files
committed
refactor: [#281] rename Environment constructor to create
Rename with_working_dir_and_tracker() to create() for cleaner, more idiomatic API. The new name is concise and clearly indicates this is the primary factory method for creating a fully-configured Environment aggregate.
1 parent eae2ba6 commit f7e342a

5 files changed

Lines changed: 12 additions & 12 deletions

File tree

docs/e2e-testing/manual/grafana-verification.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,8 +641,8 @@ docker exec <grafana_container_id> env | grep GF_SECURITY_ADMIN_PASSWORD
641641
This was a bug where the configured password wasn't being passed from the environment config to the `.env` file. It was fixed by updating:
642642

643643
- `UserInputs::with_tracker()` to accept optional Prometheus/Grafana configs
644-
- `EnvironmentContext::with_working_dir_and_tracker()` to pass configs through
645-
- `Environment::with_working_dir_and_tracker()` to accept configs
644+
- `EnvironmentContext::create()` to pass configs through
645+
- `Environment::create()` to accept configs
646646
- Create handler to pass configs instead of using defaults
647647

648648
**Solution:**

docs/refactors/plans/strengthen-domain-invariant-enforcement.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ EnvironmentCreationConfig → Build partial domain objects:
815815
816816
UserInputs validates cross-cutting invariants
817817
818-
Environment::with_working_dir_and_tracker()
818+
Environment::create()
819819
creates the complete aggregate
820820
```
821821

@@ -915,7 +915,7 @@ Then update `EnvironmentContext` to use the validated constructor:
915915

916916
```rust
917917
impl EnvironmentContext {
918-
pub fn with_working_dir_and_tracker(
918+
pub fn create(
919919
// ... params ...
920920
) -> Result<Self, UserInputsError> {
921921
let user_inputs = UserInputs::new(
@@ -960,8 +960,8 @@ impl EnvironmentContext {
960960
- [x] Create `UserInputsError` enum with `help()` method in `user_inputs.rs`
961961
- [x] Change `UserInputs::new()` to return `Result<Self, UserInputsError>`
962962
- [x] Add cross-service validation to `UserInputs::with_tracker()`
963-
- [x] Update `EnvironmentContext::with_working_dir_and_tracker()` to propagate errors
964-
- [x] Update `Environment::with_working_dir_and_tracker()` to return `Result`
963+
- [x] Update `EnvironmentContext::create()` to propagate errors
964+
- [x] Update `Environment::create()` to return `Result`
965965
- [x] Add `From<UserInputsError>` impl for `CreateConfigError` in application layer
966966
- [x] Remove duplicate validation from `EnvironmentCreationConfig::to_environment_params()`
967967
- [x] Update all call sites that create `UserInputs` directly
@@ -989,7 +989,7 @@ impl EnvironmentContext {
989989

990990
4. **Updated `EnvironmentContext`**:
991991
- `new()` uses `.expect()` since defaults always pass validation
992-
- `with_working_dir_and_tracker()` returns `Result<Self, UserInputsError>`
992+
- `create()` returns `Result<Self, UserInputsError>`
993993

994994
5. **Added `TrackerConfig::has_any_tls_configured()`** method to check TLS status
995995

@@ -1006,7 +1006,7 @@ impl EnvironmentContext {
10061006

10071007
#### Migration Notes
10081008

1009-
This change makes `Environment::with_working_dir_and_tracker()` fallible, which is a breaking change. However:
1009+
This change makes `Environment::create()` fallible, which is a breaking change. However:
10101010

10111011
1. The function is primarily called from `CreateCommandHandler::execute()` which already handles errors
10121012
2. Test helpers may need updating to use `.expect()` or propagate errors

src/application/command_handlers/create/handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl CreateCommandHandler {
234234
}
235235

236236
// Create environment aggregate from validated params
237-
let environment = Environment::with_working_dir_and_tracker(
237+
let environment = Environment::create(
238238
params.environment_name,
239239
params.provider_config,
240240
params.ssh_credentials,

src/domain/environment/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl EnvironmentContext {
223223
/// - `HttpsSectionWithoutTlsServices` if HTTPS section exists but no service uses TLS
224224
/// - `TlsServicesWithoutHttpsSection` if a service uses TLS but HTTPS section is missing
225225
#[allow(clippy::too_many_arguments)] // Public API with necessary configuration parameters
226-
pub fn with_working_dir_and_tracker(
226+
pub fn create(
227227
name: &EnvironmentName,
228228
provider_config: ProviderConfig,
229229
ssh_credentials: SshCredentials,

src/domain/environment/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ impl Environment {
310310
/// - `TlsServicesWithoutHttpsSection`: Service has TLS but HTTPS section is missing
311311
#[allow(clippy::needless_pass_by_value)] // Public API takes ownership for ergonomics
312312
#[allow(clippy::too_many_arguments)] // Public API with necessary configuration parameters
313-
pub fn with_working_dir_and_tracker(
313+
pub fn create(
314314
name: EnvironmentName,
315315
provider_config: ProviderConfig,
316316
ssh_credentials: SshCredentials,
@@ -322,7 +322,7 @@ impl Environment {
322322
working_dir: &std::path::Path,
323323
created_at: DateTime<Utc>,
324324
) -> Result<Environment<Created>, UserInputsError> {
325-
let context = EnvironmentContext::with_working_dir_and_tracker(
325+
let context = EnvironmentContext::create(
326326
&name,
327327
provider_config,
328328
ssh_credentials,

0 commit comments

Comments
 (0)