Skip to content

Instantly share code, notes, and snippets.

@asaaki
Created April 11, 2014 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asaaki/10452325 to your computer and use it in GitHub Desktop.
Save asaaki/10452325 to your computer and use it in GitHub Desktop.
ENV loader
require "yaml"
begin
application_yml = YAML.load_file(File.join(File.dirname(__FILE__), "../config/application.yml"))
global_envs = application_yml.select { |key, _| key =~ /([A-Z_])+/ }
environment = ENV["RACK_ENV"] || ENV["RAILS_ENV"] || "development"
env_envs = application_yml.fetch(environment, {})
current_envs = global_envs.merge(env_envs)
current_envs.each_pair do |key, value|
ENV[key.to_s.upcase] ||= value.to_s
end
rescue StandardError => e
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment