DotEnv
DotEnv is for managing different environment setups based on a simple textfile.
Installation
Add this line to your application's Gemfile:
gem 'dot_env', github: 'kaze/dot_env'
And then execute:
$ bundle
Usage
Basic usage:
require 'dot_env'
current_environment = DotEnv.get_environment #=> 'development'
The DotEnv.get_environment method reads a file (named .env as default). It reads, parses and sets all the environment variables found in this file. After that you can access these variables in your application simply using ENV['VARIABLE_NAME'].
If it doesn't find an .env file in your app's root directory, then sets the name of the environment -- as default -- to development.
I made assumption only about naming one variable, and this is 'APP_ENV'. DotEnv tries to detect the current environment's name from this setting.
You can use any other name for your settings file, and you can add that name as a parameter to the function: DotEnv.get_environment('path/to/settings_file')
DotEnv handles the variables as below:
- accepts shell-compatible variable names
- values could be quoted or unquoted
- supports basic shell variable expansion (
$VARIABLEand${VARIABLE}) - handles simple arrays
- handles boolean values (
true, yes, 1will betrueandfalse, no, 0will befalse, case insensitively)
After parsing every variable's type will be string, except booleans and arrays.
Contributing
- Fork it ( https://github.com/kaze/dot_env/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request