Skip to content

[RFC] Support default value for optional environment variables - #56

Draft
ameykusurkar wants to merge 3 commits into
masterfrom
default-values
Draft

[RFC] Support default value for optional environment variables#56
ameykusurkar wants to merge 3 commits into
masterfrom
default-values

Conversation

@ameykusurkar

@ameykusurkar ameykusurkar commented Jul 12, 2024

Copy link
Copy Markdown
Contributor

Prius helps us ensure that our application always boots with the
required state. However in large applications with multiple contributors,
this can cause a configuration error in an unrelated component to break
the entire application.

Providing a default value allows contributors to safely introduce new
configuration without worrying if the application breaks. For example:

Prius.get(:my_worker_pool, type: int, required: false, default: 0)

It also means that boolean flags that are optional can be made to have a
default value of true or false, rather than nil.

Note: This change does not allow you to specify a default value for
required config, for obvious reasons.

Split the logic for loading a value from parsing the value, that way we
only need to check if the env var is required in one place.
Prius helps us ensure that our application always boots with the
required state. However in large applications with multiple contributors,
this can cause a configuration error in an unrelated component to break
the entire application.

Providing a default value allows contributors to safely introduce new
configuration without worrying if the application breaks. For example:
```ruby
Prius.get(:my_worker_pool, type: int, required: false, default: 0)
```

It also means that boolean flags that are optional can be made to have a
default value of `false` rather than `nil`.

Note: This change _does not_ allow you to specify a default value for
required config, for obvious reasons.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant