Ruby

Ruby runtime

envless-env loads your encrypted environment when a Ruby app starts, decrypts it on the machine that runs it, and hands it to your code typed. The Ruby twin of @goenvless/env.

envless-env is the Envless runtime for Ruby. It fetches your environment when your app starts, decrypts it in the process, fills ENV with every name that is safe to set, and gives your code Envless.env, which reads each variable coerced to the type you set in Envless. No .env files on disk, no dotenv, no ENV["X"] typo that only fails in production.

bundle add envless-env
ruby
require "envless/env/load"

database_url = Envless.env[:DATABASE_URL]
port = Envless.env[:PORT]

It is the Ruby twin of @goenvless/env: the same loader, the same on-disk cache, the same rules for the process environment and the same error messages. A parity check in the Envless repository runs every behaviour of both packages against one fake API before each release, from pagination and the cache to which names are refused from ENV.

What this is, and what it is not

envless-envenvless-sdkenvless run
PurposeLoads variables into your running appAdministers a workspace from RubyInjects variables into any process
RunsInside your Ruby process, at bootIn scripts, back offices and CIIn front of your process, as the launcher
CredentialA machine key and a decryption keyAn API keyenvless login, or a machine key
ShapeEnvless.env[:DATABASE_URL]Envless.variables.create(...)envless run -- bin/rails server

Use envless-env when your app should fetch its own variables at boot, typically in production with a machine key. Use envless run when you would rather keep every credential in the launcher, and the Ruby SDK when you want to create projects or write variables from code. The two runtimes combine: inside envless run, envless-env reads the values the CLI injected and makes no request at all.

The surfaces

RequireWhat it gives you
envless/envEnvless::Env.load, Envless.env and its optional and client views, Envless::Env.override, the explicit loader, the errors and the crypto helpers. Loads nothing by itself
envless/env/loadEverything above, and it loads when it is required, so require it first
envless/env/railsA Railtie that loads before your Rails app is configured, and an envless view helper for client variables
bundle exec envless-env typesWrites sig/envless-env.rbs, so Steep types every variable by name

With Bundler, gem "envless-env" requires envless/env. Pass require: "envless/env/rails" in a Rails app, as the Rails page shows.

Design

Typed reads

A number reads back as an Integer, or a Float when it has a fraction, and a boolean as true or false. A missing name raises instead of returning nil, unless you read it through optional.

Secrets stay put

Envless.env refuses to be dumped, marshalled or printed with its values, so a log line or an error page shows a count, never a secret.

Ambient wins

A variable already set in ENV is never overwritten, and names that change how a process executes code, such as PATH, LD_PRELOAD or RUBYOPT, are never written at all.

Fast cold starts

The ciphertext is cached under ~/.envless/cache for 15 minutes, shared with @goenvless/env, so a restart skips the request and still decrypts in memory.

Frameworks