Env.rb is a project mainly written in Ruby, it's free.
Manage your ENV with ease
Managing your ENVironment
Many modern web applications consume and post to resources that reside at other urls, often requiring more authentication tokens than a database password. These passwords need to be stored in some location. A common, secure location that exists outside of the source directory is in the application's runtime environment.
However, consuming a resource at a url can take up to three different variables to represent the location, username, and password. If your app is consuming many endpoints the sheer number of variables can become overwhelming. Remember, the average short-term memory holds about 7 items. Certain production applications can have upwards of 50 to 100 ENV vars.
Env.rb allows you to declare environment variables like dependencies and configure multiple environments with a simple ruby DSL. It provides tools for cleaning up existing apps, exporting your Envfile to a shell-compatible format, and executing scripts within your environments.
import 'TEST'
export 'TEXT', '15'
require 'env'
ENV['HELLO_WORLD'] # => nil
ENV['TEST'] = 5
Env.load! # look for Envfile
ENV['HELLO_WORLD']
# => EnvironmentError: HELLO_WORLD is not a declared dependency
ENV['TEST'] # => 5
ENV['TEXT'] # => 15
export "PROVIDER_PASSWORD", '1234', :group => :development
group :development do
export "SERVICE_URL", 'http://username:[email protected]/path"
end
group :test do
export "SERVICE_URL", 'http://username:[email protected]/"
end
Env.load!
-same as-
Env.load! :default
Env.load! :default, :test
ENV['SERVICE_URL'] # => 'http://username:[email protected]/"
Env.load! :development
ENV['SERVICE_URL'] # => 'http://username:[email protected]/path"
export 'TEXT', '15', :mutable => false
export 'TEXT', '15', :immutable => false
ENV['TEST'] # => 15
ENV['TEST'] = 'overriding'
# => EnvironmentError: variable TEST cannot be changed
export "SERVICE", 'http://username:[email protected]/"
ENV['SERVICE'] #=> 'http://username:[email protected]/"
ENV['SERVICE'].base_uri #=> 'http://example.com/"
ENV['SERVICE'].url #=> 'http://example.com/"
ENV['SERVICE'].user #=> 'username'
ENV['SERVICE'].password #=> 'password'
ENV['SERVICE'].host #=> 'example.com'
ENV['SERVICE'].scheme #=> 'http'