aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
authorPiotr Sarnacki <drogus@gmail.com>2010-11-02 14:23:45 +0100
committerPiotr Sarnacki <drogus@gmail.com>2010-11-02 17:14:53 +0100
commit2133495b8cdcb40a68a03aa786c4353031abe49e (patch)
tree0eacb22b97e5b53df1e14382b94269ddba58efe6 /railties/lib
parentb6497d3b5a84ca5e7e15700419ddf44c096c57a2 (diff)
downloadrails-2133495b8cdcb40a68a03aa786c4353031abe49e.tar.gz
rails-2133495b8cdcb40a68a03aa786c4353031abe49e.tar.bz2
rails-2133495b8cdcb40a68a03aa786c4353031abe49e.zip
Properly handle other databases in 'plugin new' generator
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/rails/generators/app_base.rb27
-rw-r--r--railties/lib/rails/generators/rails/app/app_generator.rb18
-rw-r--r--railties/lib/rails/generators/rails/app/templates/Gemfile4
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/templates/Gemfile2
4 files changed, 29 insertions, 22 deletions
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb
index 0bf5ee86b1..b7a4b16f10 100644
--- a/railties/lib/rails/generators/app_base.rb
+++ b/railties/lib/rails/generators/app_base.rb
@@ -108,6 +108,15 @@ module Rails
end
end
+ def database_gemfile_entry
+ entry = ""
+ unless options[:skip_active_record]
+ entry = "gem '#{gem_for_database}'"
+ entry << ", :require => '#{require_for_database}'" if require_for_database
+ end
+ entry
+ end
+
def rails_gemfile_entry
if options.dev?
<<-GEMFILE
@@ -133,6 +142,24 @@ gem 'rails', '#{Rails::VERSION::STRING}'
end
end
+ def gem_for_database
+ # %w( mysql oracle postgresql sqlite3 frontbase ibm_db )
+ case options[:database]
+ when "oracle" then "ruby-oci8"
+ when "postgresql" then "pg"
+ when "sqlite3" then "sqlite3-ruby"
+ when "frontbase" then "ruby-frontbase"
+ when "mysql" then "mysql2"
+ else options[:database]
+ end
+ end
+
+ def require_for_database
+ case options[:database]
+ when "sqlite3" then "sqlite3"
+ end
+ end
+
def bundle_if_dev_or_edge
bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle')
run "#{bundle_command} install" if dev_or_edge?
diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb
index e2d2ae71ba..7a6a7972d2 100644
--- a/railties/lib/rails/generators/rails/app/app_generator.rb
+++ b/railties/lib/rails/generators/rails/app/app_generator.rb
@@ -306,24 +306,6 @@ module Rails
ActiveSupport::SecureRandom.hex(64)
end
- def gem_for_database
- # %w( mysql oracle postgresql sqlite3 frontbase ibm_db )
- case options[:database]
- when "oracle" then "ruby-oci8"
- when "postgresql" then "pg"
- when "sqlite3" then "sqlite3-ruby"
- when "frontbase" then "ruby-frontbase"
- when "mysql" then "mysql2"
- else options[:database]
- end
- end
-
- def require_for_database
- case options[:database]
- when "sqlite3" then "sqlite3"
- end
- end
-
def mysql_socket
@mysql_socket ||= [
"/tmp/mysql.sock", # default
diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile
index 4a37f675ad..86b9e8f40c 100644
--- a/railties/lib/rails/generators/rails/app/templates/Gemfile
+++ b/railties/lib/rails/generators/rails/app/templates/Gemfile
@@ -2,9 +2,7 @@ source 'http://rubygems.org'
<%= rails_gemfile_entry -%>
-<% unless options[:skip_active_record] -%>
-gem '<%= gem_for_database %>'<% if require_for_database %>, :require => '<%= require_for_database %>'<% end %>
-<% end -%>
+<%= database_gemfile_entry -%>
# Use unicorn as the web server
# gem 'unicorn'
diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile b/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile
index 928ea8b9c4..29900c93dc 100644
--- a/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile
+++ b/railties/lib/rails/generators/rails/plugin_new/templates/Gemfile
@@ -3,7 +3,7 @@ source "http://rubygems.org"
<%= rails_gemfile_entry -%>
<% if full? -%>
- gem "sqlite3-ruby", :require => "sqlite3"
+<%= database_gemfile_entry -%>
<% end -%>
if RUBY_VERSION < '1.9'