Permalink
Browse files

Rake task to write out config

  • Loading branch information...
1 parent fe2938c commit 40ddbf0b8a0d5a3ac5f44e159af2d8cc31a8c450 @tpope committed Jan 31, 2012
Showing with 17 additions and 4 deletions.
  1. +2 −0 README.markdown
  2. +7 −0 lib/rails-default-database.rake
  3. +8 −4 lib/rails-default-database.rb
View
@@ -8,6 +8,8 @@ Gemfile) will be automatically configured with Rails defaults:
gem 'rails-default-database'
You can still override the defaults by creating `config/database.yml`.
+Use `rake db:config` to create `config/database.yml` with the defaults
+that would have been assumed.
License
-------
@@ -0,0 +1,7 @@
+desc 'Write out config/database.yml from rails-default-database'
+task 'db:config' do
+ contents = Rails.configuration.database_configuration.to_yaml
+ File.open(Rails.root.join('config/database.yml'), 'w') do |f|
+ f.puts contents.sub(/^---\n/, '')
+ end
+end
@@ -7,12 +7,10 @@ def database_configuration_with_default
rescue Errno::ENOENT
end || {}
- default_config.merge(config_file)
+ default_database_configuration.merge(config_file)
end
- private
-
- def default_config
+ def default_database_configuration
name = File.basename(root)
generator = begin
require 'pg'
@@ -62,3 +60,9 @@ def default_config
alias_method_chain :database_configuration, :default
end
+
+class RailsDefaultDatabaseRailtie < Rails::Railtie
+ rake_tasks do
+ load 'rails-default-database.rake'
+ end
+end

0 comments on commit 40ddbf0

Please sign in to comment.