Typed ENV contracts with validation and sample generation.
Env Contract lets you define required and optional environment variables with types, defaults, and descriptions. It validates values at boot time and provides a env-contract CLI to generate .env.sample output.
This is useful for services that need clear, enforceable configuration contracts and easy onboarding.
- Enforce required configuration at boot time
- Generate
.env.samplefiles for onboarding and docs - Prevent misconfigurations in multi-env deployments
- Ruby 3.0+
Also check out these related gems:
- Cache Coalescer: https://github.com/Elysium-Arc/cache-coalescer
- Cache SWR: https://github.com/Elysium-Arc/cache-swr
- Faraday Hedge: https://github.com/Elysium-Arc/faraday-hedge
- Rack Idempotency Kit: https://github.com/Elysium-Arc/rack-idempotency-kit
# Gemfile
gem "env-contract"EnvContract.define do
required :DATABASE_URL, type: :string, desc: "Primary DB"
optional :REDIS_URL, type: :string
optional :RETRIES, type: :integer, default: 3
end
values = EnvContract.load!:string:integer:float:boolean:json
Generate .env.sample:
env-contract > .env.sample# config/application.rb
config.env_contract.validate_on_boot = truebundle exec rake release