DbCharmerEnvUrls

DbCharmerEnvUrls extracts database urls from the environment and adds them to ActiveRecord::Base.configurations in a format expected by DbCharmer.

Installation

Add this line to your application's Gemfile:

gem 'db_charmer_env_urls'

And then execute:

$ bundle

Or install it yourself as:

$ gem install db_charmer_env_urls

Usage

DbCharmerEnvUrls parses env variables and adds them to the environment's configuration hash. ENV variables appended with _DATABASE_URL (eg. SLAVE_DATABASE_URL) will be added to the configurations.

[1] pry(main)> ENV
=> {}
[2] pry(main)> ActiveRecord::Base.configurations
{
  "production" => {
    "adapter" => "postgres",
    "database" => "my_database" 
  }
}
[1] pry(main)> ENV
=> {"SLAVE_DATABASE_URL"=>"postgres://localhost:5432/name?encoding=UTF-8"}
[2] pry(main)> ActiveRecord::Base.configurations
{
  "production" => {
    "adapter" => "postgres",
    "database" => "my_database",
    "slave" => {
      "adapter" => "postgres",
      "host" => "localhost",
      "port" => 5432,
      "database" => "name",
      "encoding" => "UTF-8"
    }
  }
}

Contributing

  1. Fork it ( https://github.com/[my-github-username]/db_charmer_env_urls/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request