Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #########################################################
- #
- # This method takes a db connection url and returns rails
- # config YAML
- #
- ##########################################################
- require "uri"
- require "yaml"
- db_url = "mysql2://ted:password@example.net:3306/test?reconnect=false"
- uri = URI.parse(ENV["db_url"] || db_url)
- qs = Hash[URI::decode_www_form(uri.query)]
- ui = uri.userinfo.split(':')
- config = {
- "production" => {
- "encoding" => qs["encoding"] || "utf-8",
- "adapter" => uri.scheme,
- "host" => uri.host,
- "port" => uri.port || 3306,
- "database" => uri.path[1..-1],
- "username" => ui.first,
- "password" => ui.last,
- "reconnect" => qs["reconnect"] || true,
- "pool" => qs["pool"] || 5,
- }.to_yaml
- puts config
- # ---
- # production:
- # encoding: utf-8
- # adapter: mysql2
- # host: example.net
- # port: 3306
- # database: test
- # username: ted
- # password: password
- # reconnect: 'false'
- # pool: 5
Add Comment
Please, Sign In to add comment