Skip to content

Instantly share code, notes, and snippets.

@burtlo
Created November 18, 2010 00:34
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 burtlo/704434 to your computer and use it in GitHub Desktop.
Save burtlo/704434 to your computer and use it in GitHub Desktop.
Environment with defaults, system overrides, and user overrides
require 'yaml'
require 'active_support'
WINDOWS_PLATFORM = /mswin|win32|mingw/ unless defined?(WINDOWS_PLATFORM)
$env = YAML.load_file("#{File.dirname(__FILE__)}/environment.yml")
DEFAULT_ENVIRONMENT = "#{RUBY_PLATFORM =~ WINDOWS_PLATFORM ? 'windows_' : ''}default"
$default_env = $env[DEFAULT_ENVIRONMENT]
#
# Allow user to specify an environment with env=?
# Otherwise use the HOSTNAME (Linux) or COMPUTERNAME (Windows)
#
SPECIFIC_ENVIRONMENT = (ENV['env'] || ENV['HOSTNAME'] || ENV['COMPUTERNAME'] || "").downcase
if SPECIFIC_ENVIRONMENT and $env.include?(SPECIFIC_ENVIRONMENT)
$log.info "Loading Environment: #{(SPECIFIC_ENVIRONMENT).downcase.strip} #{RUBY_PLATFORM =~ WINDOWS_PLATFORM ? '(WINDOWS)' : ''}"
$specific_env = $env[(SPECIFIC_ENVIRONMENT).downcase.strip]
$env = $default_env.deep_merge($specific_env)
end
#
# When the environment is loaded at run-time, the system will use the default
# values and then merge the specific values of the environment. As most of
# our properties remain the same, this allows for easy configuration.
#
# Windows Environments have some different requirements for some of the paths,
# scripts and tools.
#
---
default: &DEFAULT
host:
name: testsystem
http_port: '8080'
username: defaultuser
database:
host: db01/db01
username:
password:
test:
browser: FIREFOX
#
# Windows Overrides
#
windows_default: &WIN_DEFAULT
<<: *DEFAULT
test:
browser: IE
#
# Custom User/System Environments
#
profile1:
host:
name: usersystem1
username: user
database:
username: user_db
password: foobar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment