diff options
author | Terence Lee <hone02@gmail.com> | 2013-02-21 01:13:10 +1100 |
---|---|---|
committer | Terence Lee <hone02@gmail.com> | 2013-02-21 01:25:05 +1100 |
commit | 4bdaf95b82a1358b11bbfb857a1ac2790136a4ef (patch) | |
tree | 3882f08781365e81a2aa9f3046d7175b2dae4574 /railties | |
parent | ebae71a67a6c4d0421efd932b2af88c48b8b1c7c (diff) | |
download | rails-4bdaf95b82a1358b11bbfb857a1ac2790136a4ef.tar.gz rails-4bdaf95b82a1358b11bbfb857a1ac2790136a4ef.tar.bz2 rails-4bdaf95b82a1358b11bbfb857a1ac2790136a4ef.zip |
standardize database_configuration to a hash
make connection_url_to_hash a class method
This als prevents loading database.yml if it doesn't exist
but DATABASE_URL does
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/application/configuration.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 2c7ddd86e7..1b88b834c7 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -101,8 +101,12 @@ module Rails # contents of the file are processed via ERB before being sent through # YAML::load. def database_configuration - require 'erb' - YAML.load ERB.new(IO.read(paths["config/database"].first)).result + if ENV['DATABASE_URL'] + {Rails.env => ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.connection_url_to_hash(ENV['DATABASE_URL']).stringify_keys} + else + require 'erb' + YAML.load ERB.new(IO.read(paths["config/database"].first)).result + end rescue Psych::SyntaxError => e raise "YAML syntax error occurred while parsing #{paths["config/database"].first}. " \ "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \ |