Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Rake task to write out config

  • Loading branch information...
commit 40ddbf0b8a0d5a3ac5f44e159af2d8cc31a8c450 1 parent fe2938c
Tim Pope authored January 30, 2012
2  README.markdown
Source Rendered
@@ -8,6 +8,8 @@ Gemfile) will be automatically configured with Rails defaults:
8 8
     gem 'rails-default-database'
9 9
 
10 10
 You can still override the defaults by creating `config/database.yml`.
  11
+Use `rake db:config` to create `config/database.yml` with the defaults
  12
+that would have been assumed.
11 13
 
12 14
 License
13 15
 -------
7  lib/rails-default-database.rake
... ...
@@ -0,0 +1,7 @@
  1
+desc 'Write out config/database.yml from rails-default-database'
  2
+task 'db:config' do
  3
+  contents = Rails.configuration.database_configuration.to_yaml
  4
+  File.open(Rails.root.join('config/database.yml'), 'w') do |f|
  5
+    f.puts contents.sub(/^---\n/, '')
  6
+  end
  7
+end
12  lib/rails-default-database.rb
@@ -7,12 +7,10 @@ def database_configuration_with_default
7 7
       rescue Errno::ENOENT
8 8
       end || {}
9 9
 
10  
-    default_config.merge(config_file)
  10
+    default_database_configuration.merge(config_file)
11 11
   end
12 12
 
13  
-  private
14  
-
15  
-  def default_config
  13
+  def default_database_configuration
16 14
     name = File.basename(root)
17 15
     generator = begin
18 16
       require 'pg'
@@ -62,3 +60,9 @@ def default_config
62 60
 
63 61
   alias_method_chain :database_configuration, :default
64 62
 end
  63
+
  64
+class RailsDefaultDatabaseRailtie < Rails::Railtie
  65
+  rake_tasks do
  66
+    load 'rails-default-database.rake'
  67
+  end
  68
+end

0 notes on commit 40ddbf0

Please sign in to comment.
Something went wrong with that request. Please try again.