Skip to content

Instantly share code, notes, and snippets.

@manuelmeurer
Created February 26, 2011 05:41
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 manuelmeurer/844988 to your computer and use it in GitHub Desktop.
Save manuelmeurer/844988 to your computer and use it in GitHub Desktop.
My app config setup
# in config/initializers/
# prefixed with 'aaa_' so it's loaded first and app configs can be used in the following initializers
require 'ostruct'
config = File.read(Rails.root.join('config', 'app_config.yml'))
unless config.empty?
::AppConfig = OpenStruct.new(YAML.load(ERB.new(config).result).with_indifferent_access)
%w(development test production).each do |env|
if (env_config = AppConfig.delete_field(env)).present? && Rails.env == env
env_config.each do |k, v|
if AppConfig.send(k).present?
AppConfig.send(k).merge!(v)
else
AppConfig.send([k, '='].join, v)
end
end
end
end
end
# in config/
# ERb can be used
s3:
key: devkey
secret: devsecret
foo:
bar:
baz: <%= 1.day %>
production:
s3:
key: realkey
secret: realkey
# And this is how you use it in your code
AppConfig.foo[:bar][:baz] # 86400 (24*60*60)
AppConfig.s3[:key] # 'devkey' in development and test environment, 'realkey' in production environment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment