Created
November 12, 2011 18:05
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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