0.0
The project is in a healthy, maintained state
Define required/optional ENV variables with type casting and validation.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 1.17
>= 13.0
~> 3.12
~> 0.22
 Project Readme

Env Contract

Gem Version Gem Downloads Ruby CI GitHub Release Rails Elysium Arc

Typed ENV contracts with validation and sample generation.

About

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.

Use Cases

  • Enforce required configuration at boot time
  • Generate .env.sample files for onboarding and docs
  • Prevent misconfigurations in multi-env deployments

Compatibility

  • Ruby 3.0+

Elysium Arc Reliability Toolkit

Also check out these related gems:

Installation

# Gemfile

gem "env-contract"

Usage

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!

Types

  • :string
  • :integer
  • :float
  • :boolean
  • :json

CLI

Generate .env.sample:

env-contract > .env.sample

Rails

# config/application.rb
config.env_contract.validate_on_boot = true

Release

bundle exec rake release