From 290983be3114cd48f63265466abb57b15cbfb8f5 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 25 Feb 2006 18:41:13 +0000 Subject: Added -d/--database option to the rails command, so you can do "rails --database=sqlite2 myapp" to start a new application preconfigured to use SQLite2 as the database. Removed the configuration examples from SQLite and PostgreSQL from the default MySQL configuration [DHH] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3642 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../generators/applications/app/app_generator.rb | 34 ++++++++++++---------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'railties/lib/rails_generator') diff --git a/railties/lib/rails_generator/generators/applications/app/app_generator.rb b/railties/lib/rails_generator/generators/applications/app/app_generator.rb index 0818167fc4..2456f02451 100644 --- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb @@ -4,16 +4,13 @@ class AppGenerator < Rails::Generator::Base DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) - default_options :gem => true, :shebang => DEFAULT_SHEBANG - mandatory_options :source => "#{File.dirname(__FILE__)}/../../../../.." + default_options :db => "mysql", :shebang => DEFAULT_SHEBANG + mandatory_options :source => "#{File.dirname(__FILE__)}/../../../../.." def initialize(runtime_args, runtime_options = {}) super usage if args.empty? @destination_root = args.shift - unless RUBY_PLATFORM =~ /mswin32/ - @socket = MYSQL_SOCKET_LOCATIONS.find { |f| File.exists?(f) } - end end def manifest @@ -35,9 +32,9 @@ class AppGenerator < Rails::Generator::Base m.template "helpers/test_helper.rb", "test/test_helper.rb" # database.yml and .htaccess - m.template "configs/database.yml", "config/database.yml", :assigns => { + m.template "configs/databases/#{options[:db]}.yml", "config/database.yml", :assigns => { :app_name => File.basename(File.expand_path(@destination_root)), - :socket => @socket + :socket => options[:db] == "mysql" ? mysql_socket_location : nil } m.template "configs/routes.rb", "config/routes.rb" m.template "configs/apache.conf", "public/.htaccess" @@ -64,15 +61,15 @@ class AppGenerator < Rails::Generator::Base m.template "html/#{file}.html", "public/#{file}.html" end - m.template "html/favicon.ico", "public/favicon.ico" - m.template "html/robots.txt", "public/robots.txt" + m.template "html/favicon.ico", "public/favicon.ico" + m.template "html/robots.txt", "public/robots.txt" m.file "html/images/rails.png", "public/images/rails.png" # Javascripts - m.file "html/javascripts/prototype.js", "public/javascripts/prototype.js" - m.file "html/javascripts/effects.js", "public/javascripts/effects.js" - m.file "html/javascripts/dragdrop.js", "public/javascripts/dragdrop.js" - m.file "html/javascripts/controls.js", "public/javascripts/controls.js" + m.file "html/javascripts/prototype.js", "public/javascripts/prototype.js" + m.file "html/javascripts/effects.js", "public/javascripts/effects.js" + m.file "html/javascripts/dragdrop.js", "public/javascripts/dragdrop.js" + m.file "html/javascripts/controls.js", "public/javascripts/controls.js" # Docs m.file "doc/README_FOR_APP", "doc/README_FOR_APP" @@ -94,9 +91,14 @@ class AppGenerator < Rails::Generator::Base opt.separator 'Options:' opt.on("--ruby [#{DEFAULT_SHEBANG}]", "Path to the Ruby binary of your choice.") { |options[:shebang]| } - opt.on("--without-gems", - "Don't use the Rails gems for your app.", - "WARNING: see note below.") { |options[:gem]| } + + opt.on("-d", "--database=name", String, + "Preconfigure for selected database (options: mysql/postgresql/sqlite2/sqlite3).", + "Default: mysql") { |options[:db]| } + end + + def mysql_socket_location + RUBY_PLATFORM =~ /mswin32/ ? MYSQL_SOCKET_LOCATIONS.find { |f| File.exists?(f) } : nil end -- cgit v1.2.3