Skip to content

Instantly share code, notes, and snippets.

@noxqsgit
Last active October 13, 2015 08:48
Show Gist options
  • Save noxqsgit/4170142 to your computer and use it in GitHub Desktop.
Save noxqsgit/4170142 to your computer and use it in GitHub Desktop.
ruby (rails) app config file
# ...
# CFG {
require 'rails'
CFG_NAME = (->(; d, b) {
d, b = File.split Dir.pwd
b == 'app' ? File.basename(d) : b
})[]
CFG_DIR = "#{ Dir.home }/.apps/#{ CFG_NAME }"
require "#{ CFG_DIR }/cfg"
CFG['development'] = CFG[:dev]
CFG['production'] = CFG[:prod]
CFG['test'] = CFG[:test]
CFG[Rails.env][:init][]
# } CFG
# ...
# CFG {
require 'rails'
# PLEASE USE A CONFIGURATION FILE FOR DEVELOPMENT AS WELL
if Rails.env == 'production'
CFG_NAME = (->(; d, b) {
d, b = File.split Dir.pwd
b == 'app' ? File.basename(d) : b
})[]
CFG_DIR = "#{ Dir.home }/.apps/#{ CFG_NAME }"
require "#{ CFG_DIR }/cfg"
CFG['development'] = CFG[:dev]
CFG['production'] = CFG[:prod]
CFG['test'] = CFG[:test]
CFG[Rails.env][:init][]
else
CFG = { dev: {}, test: {}, prod: {} }
end
# } CFG
CFG = {
test: {},
dev: {},
prod: {
db_name: '...',
db_user: '...',
db_pass: '...',
init: ->() {
File.symlink '/path/to/uploads',
'public/system' unless File.exists? 'public/system'
},
}
}
development:
adapter: postgresql
encoding: utf8
database: <%= CFG[:dev][:db_name] %>
pool: 5
username: <%= CFG[:dev][:db_user] %>
password: <%= CFG[:dev][:db_pass] %>
host: <%= CFG[:dev][:db_host] or 'localhost' %>
test:
adapter: postgresql
encoding: utf8
database: <%= CFG[:test][:db_name] %>
pool: 5
username: <%= CFG[:test][:db_user] %>
password: <%= CFG[:test][:db_pass] %>
host: <%= CFG[:test][:db_host] or 'localhost' %>
production:
adapter: postgresql
encoding: utf8
database: <%= CFG[:prod][:db_name] %>
pool: 5
username: <%= CFG[:prod][:db_user] %>
password: <%= CFG[:prod][:db_pass] %>
host: <%= CFG[:prod][:db_host] or 'localhost' %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment