Skip to content

opencounter/EnvRq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EnvRq

Simple environment variable validation / documentation in ~100 LOC.

Features

  • Severity levels (Info, Warning, Fatal).
  • Type checking
  • Optional ENV variable descriptions.
  • Overidable issue handlers (by severity level).

Install

Add to your Gemfile and bundle.

gem "env_rq", git: "https://github.com/opencounter/EnvRq"

Run Specs

bundle exec rake test

Usage

require('env_rq')

EnvRq.validate do |e|
  # expect ENV_WITH_DESC to exist and warn if not (prints to stout in orange)
  # showing description.
  e.warn("ENV_WITH_DESC", desc: "Airbrake project to assoicate errors with")

  # expect INT_ENV to be of type integer
  e.warn("INV_ENV", type: :int)
  # and URL_ENV to be a valid URL
  e.warn("URL_ENV", type: :url)

  # expect MISSING_ENV not to be set and print (in blue) if it is
  e.info("MISSING_ENV", desc: "this env is no longer used", exclude: true)

  # checks that apply only in production
  unless Rails.env.production?
    # print in red and raise if this ENV is set!
    e.fatal("NEVER_SET_ENV", desc: "OH MY GOODNESS", exclude: true)
  end

  # override the warn level handler to send issues to Airbrake
  send_to_airbrake = lambda do |issues|
    issues_string = issues.map { |i| i[:requirement].env_var }.join(", ")
    Airbrake.notify("ENV issues: variables\n#{issues_string}" )
  end
  e.handleIssues(:warn, send_to_airbrake)
end

FAQ

Note the 100 LOC count does not include the tests.

About

Minimal ENV validation / documentation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published