Skip to content

Commit

Permalink
refactor: Create properties such as NotExists and IsNotOptional (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrDave1999 authored Jun 28, 2024
1 parent 84b6696 commit b45f5cd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/Loader/EnvFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,18 @@ internal class EnvFile
/// </summary>
public bool Exists { get; set; } = true;

/// <summary>
/// Checks if the .env file does not exist.
/// </summary>
public bool NotExists => !Exists;

/// <summary>
/// A value indicating whether the existence of the .env file is optional or not.
/// </summary>
public bool Optional { get; set; }

/// <summary>
/// Checks if the .env file is not optional.
/// </summary>
public bool IsNotOptional => !Optional;
}
2 changes: 1 addition & 1 deletion src/Loader/EnvLoader.HelperMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private void StartFileLoading(EnvFile envFile)
envFile.Path = Path.Combine(_configuration.BasePath, envFile.Path);
envFile.Exists = ReadFileContents(envFile);

if (!envFile.Exists && !envFile.Optional)
if (envFile.NotExists && envFile.IsNotOptional)
_validationResult.Add(errorMsg: string.Format(FileNotFoundMessage, envFile.Path));
}

Expand Down
4 changes: 2 additions & 2 deletions src/Loader/EnvLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public IEnvironmentVariablesProvider LoadEnv(out EnvValidationResult result)
var envLocal = envFiles[2];
// Defines the default environment.
Env.CurrentEnvironment = EnvironmentNames.Development[0];
if (!envDevelopmentLocal.Exists && !envDevLocal.Exists && !envLocal.Exists)
if (envDevelopmentLocal.NotExists && envDevLocal.NotExists && envLocal.NotExists)
_validationResult.Add(errorMsg: FormatLocalFileNotPresentMessage());
}
else
Expand All @@ -94,7 +94,7 @@ public IEnvironmentVariablesProvider LoadEnv(out EnvValidationResult result)
var envEnvironmentLocal = envFiles[0];
// .env.local
var envLocal = envFiles[1];
if (!envEnvironmentLocal.Exists && !envLocal.Exists)
if (envEnvironmentLocal.NotExists && envLocal.NotExists)
_validationResult.Add(errorMsg: FormatLocalFileNotPresentMessage(environmentName: environment));
}

Expand Down

0 comments on commit b45f5cd

Please sign in to comment.