Skip to content

Instantly share code, notes, and snippets.

@yorickpeterse
Created March 3, 2014 10:34
Show Gist options
  • Save yorickpeterse/9322373 to your computer and use it in GitHub Desktop.
Save yorickpeterse/9322373 to your computer and use it in GitHub Desktop.
Universal Ruby Environment/Mode Variables

This Gist aims to get some discussion going and throw some ideas around about introducing a more universal way to configure the environment/mode of Ruby applications and libraries (where applicable).

When speaking about the environment/mode (referred to as "environment" from this point on) we're speaking about the variable/option that specifies a alternative set of configuration options to use. That is, separate database options, hostnames and so on. A basic example of this is the standard Rails database configuration file:

development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

test:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: sqlite3
  database: db/production.sqlite3
  pool: 5
  timeout: 5000

Currently different frameworks/libraries use different environment variable names to change the application's environment (sometimes also providing CLI options for this). For example, Rack uses RACK_ENV, Rails uses both RACK_ENV and RAILS_ENV (I think), daemon-kit uses DAEMON_ENV. There are the ones that I can think of, I would not be surprised if there are more out there.

What I, and probably others would like to see is a universal environment variable that can be used to set the application's environment. That is, all frameworks (or at least the ones that are willing to) would respond to the same variable. Doing so would simplify configuration management as one no longer has to set a handful of variables to achieve something that should be trivial.

I asked a few noteworthy project owners/maintainers about their opinion in the following Tweet: https://twitter.com/YorickPeterse/status/437948328420990976. Some of the proposed variable names from this are as following:

  • RUBY_ENV
  • ENV
  • RUBY_MODE

To me personally the name does not matter that much, though I think ENV could potentially collide with non Ruby related settings. As such I'd like to receive feedback from those that are interested so we can come up with a mutually agreed upon standard.

@yorickpeterse
Copy link
Author

In #ruby-lang "darix" suggested APP_ENV.

@darix
Copy link

darix commented Mar 3, 2014

APP_ENV

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment