Skip to content

Instantly share code, notes, and snippets.

@maxidr
Created October 11, 2012 13:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save maxidr/3872271 to your computer and use it in GitHub Desktop.
Save maxidr/3872271 to your computer and use it in GitHub Desktop.
Allows you to set environment variables in a YAML file at config/env.yml (from http://railswizard.org of intridea)
# in config/env.yml
defaults: &defaults
ENV_YAML: true
development:
<<: *defaults
test:
<<: *defaults
production:
<<: *defaults
# in lib/env_yaml.rb
require 'yaml'
begin
env_yaml = YAML.load_file(File.dirname(__FILE__) + '/../config/env.yml')
if env_hash = env_yaml[ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development']
env_hash.each_pair do |k,v|
ENV[k] = v.to_s
end
end
rescue StandardError => e
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment