Add gem and file for environment variables?
1) None
2) Add .env with Foreman
Purpose
Use dotenv gem + .env file + initializers by default
Checklist for changes:
[x] Add gem 'dotenv-rails' to Gemfile
[x] Add .env.sample file to the app root with content:
# NOTE: don't forget to:
# 1) add a variable to .env on server
# 2) stop and start puma process (right after you added new variables)
RAILS_ENV=development
* [x] Add script to `setup` script(copies vars from env sample file to env):
```ruby
unless File.exist?(".env")
cp ".env.sample", ".env"
end
[x] Add script to update script(updates env vars from sample file):
def env_sample_vars
File.read('.env.sample').each_line.inject({}) do |variables, line|
variable = line.split('=')[0]
variables.merge({variable => line})
end
end
File.open('.env', 'a') do |file|
env_sample_vars.each do |var_name, var_definition|
file << var_definition unless env_file.include?(var_name)
end
end
end
if File.exist?(".env")
try_to_add_new_env_vars
else
cp ".env.sample", ".env"
end
More info about `setup` and `update` scripts [here](https://github.com/datarockets/rails_apps_composer/issues/19)
###### P.S. Ping me if you are not agree, or have better idea.
* [ ] Check figaro gem, and update if this will be necussary:
Conversation
Purpose
Use
dotenv
gem +.env
file + initializers by defaultChecklist for changes:
[x] Add
gem 'dotenv-rails'
to Gemfile[x] Add
.env.sample
file to the app root with content:RAILS_ENV=development
update
script(updates env vars from sample file):def try_to_add_new_env_vars env_file = File.read('.env')
File.open('.env', 'a') do |file| env_sample_vars.each do |var_name, var_definition| file << var_definition unless env_file.include?(var_name) end end end
if File.exist?(".env") try_to_add_new_env_vars else cp ".env.sample", ".env" end