typed_env_config v0.2.0
typed_env_config
typed_env_config is a Crystal library for loading environment configurations/variables with type safety. We do so without cluttering the ENV variable.
Installation
-
Add the dependency to your
shard.yml:dependencies: typed_env_config: github: systatum/typed_env_config -
Run
shards install
Usage
First, define a configuration class. It must include TypedEnvConfig.
class AppSettings
include TypedEnvConfig
field ligo_app_cors_whitelist : String, default: ""
field ligo_undefined_key : String, default: "undefined"
end
Given the following configuration file aptly named app_settings.yml:
default: &default
outwardly_inherited: true
ligo:
app: &ligo_app
cors_whitelist: "*"
deeply_inherited: true
production:
<<: *default
ligo:
app:
<<: *ligo_app
cors_whitelist: "https://systatum.com"
development:
<<: *default
ligo:
app:
<<: *ligo_app
We can then load the configuration from a YAML file in this way:
dev_config = AppSettings.load_from_yaml_file!("spec/fixtures/app_settings.yml", "development")
dev_config.ligo_app_cors_whitelist
Easy, and type-safe!
Contributing
- Fork it (https://github.com/systatum/typed_env_config/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
Create with ⸜(。˃ ᵕ ˂ )⸝♡ at Systatum.
Repository
typed_env_config
Owner
Statistic
- 0
- 0
- 1
- 0
- 0
- about 6 hours ago
- April 13, 2025
License
MIT License
Links
Synced at
Fri, 21 Nov 2025 19:00:01 GMT
Languages