Skip to content

Instantly share code, notes, and snippets.

@hmcfletch
Created December 29, 2011 08:41
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 hmcfletch/1532985 to your computer and use it in GitHub Desktop.
Save hmcfletch/1532985 to your computer and use it in GitHub Desktop.
Rails project wide and personal configuration files
require File.expand_path('../boot', __FILE__)
require 'rails/all'
module MyApp
class Application < Rails::Application
# you app configuration code
end
end
{ :config => :CONFIG,
:database => :DATABASE,
:facebook => :FACEBOOK,
:mailer => :MAILER,
:paypal_adaptive => :PAYPAL,
:s3 => :S3 }.each_pair do |file_name, variable_name|
config = YAML.load_file(File.join("#{Rails.root.to_s}/config", "#{file_name}.yml"))[Rails.env].symbolize_keys # Load in the defaults.
override = File.join("#{Rails.root.to_s}/config", "#{file_name}.personal.yml") # Check for personal settings.
config.merge!(YAML.load_file(override)[Rails.env].symbolize_keys) if File.exists?(override)
self.class.const_set(variable_name, config)
end
# generates the following global constants:
# CONFIG
# DATABASE
# FACEBOOK
# MAILER
# PAYPAL
# S3
# don't forget to add config/*.personal.yml to your .gitignore
development:
name: MyTotallySweetName
host: lvho.st:3000
user_dev_tweaks: true
test:
name: AppName
host: 127.0.0.1:3000
development:
name: AppName
host: lvho.st:3000
user_dev_tweaks: false
production:
name: AppName
host: sweetdomain.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment