Skip to content

Instantly share code, notes, and snippets.

@jfgomez86
Created November 12, 2011 18:05
Show Gist options
  • Select an option

  • Save jfgomez86/1360891 to your computer and use it in GitHub Desktop.

Select an option

Save jfgomez86/1360891 to your computer and use it in GitHub Desktop.
Script that generates a database.yml file based on some input. Used for CI environments mainly.
require 'yaml'
class DatabaseYML
attr_accessor :project_name, :config
DEFAULT_OPTIONS = {
"adapter" => "mysql2",
"encoding" => "utf8",
"reconnect" => false,
"pool" => 5,
"username" => "jenkins",
"password" => ""
}
def initialize(project_name, env = "test")
@env, @project_name = env.to_s, project_name.downcase.gsub(/\s/, "_")
@options = DEFAULT_OPTIONS # TODO: Add customization for options
@config = { @env => {} }
end
def to_s
setup_config!
@config.to_yaml
end
private
def setup_config!
@config[@env] = options_with_database!(@project_name)
end
def options_with_database!(project_name)
@options["database"] = @project_name
@config[@env] = @options
end
end
if __FILE__ == $0
# TODO: On next release please consider using OptionParser
config = DatabaseYML.new(*ARGV)
print config
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment