aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/generators/app_base.rb
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/rails/generators/app_base.rb')
-rw-r--r--railties/lib/rails/generators/app_base.rb71
1 files changed, 48 insertions, 23 deletions
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb
index 93db5106ce..e8709b2ddd 100644
--- a/railties/lib/rails/generators/app_base.rb
+++ b/railties/lib/rails/generators/app_base.rb
@@ -10,7 +10,8 @@ module Rails
module Generators
class AppBase < Base
DATABASES = %w( mysql oracle postgresql sqlite3 frontbase ibm_db )
- JAVASCRIPTS = %w( prototype jquery )
+ JDBC_DATABASES = %w( jdbcmysql jdbcsqlite3 jdbcpostgresql )
+ DATABASES.concat(JDBC_DATABASES)
attr_accessor :rails_template
add_shebang_option!
@@ -36,11 +37,11 @@ module Rails
class_option :database, :type => :string, :aliases => "-d", :default => "sqlite3",
:desc => "Preconfigure for selected database (options: #{DATABASES.join('/')})"
- class_option :javascript, :type => :string, :aliases => "-j", :default => "prototype",
- :desc => "Preconfigure for selected javascript library (options: #{JAVASCRIPTS.join('/')})"
+ class_option :javascript, :type => :string, :aliases => '-j', :default => 'jquery',
+ :desc => 'Preconfigure for selected JavaScript library'
class_option :skip_javascript, :type => :boolean, :aliases => "-J", :default => false,
- :desc => "Skip javascript files"
+ :desc => "Skip JavaScript files"
class_option :dev, :type => :boolean, :default => false,
:desc => "Setup the #{name} with Gemfile pointing to your Rails checkout"
@@ -116,53 +117,73 @@ module Rails
end
def database_gemfile_entry
- entry = options[:skip_active_record] ? "" : "gem '#{gem_for_database}'"
- if options[:database] == 'mysql'
- if options.dev? || options.edge?
- entry += ", :git => 'git://github.com/brianmario/mysql2.git'"
- else
- entry += "\n# gem 'mysql2', :git => 'git://github.com/brianmario/mysql2.git'"
- end
- end
- entry
+ options[:skip_active_record] ? "" : "gem '#{gem_for_database}'\n"
+ end
+
+ def include_all_railties?
+ !options[:skip_active_record] && !options[:skip_test_unit]
+ end
+
+ def comment_if(value)
+ options[value] ? '#' : ''
end
def rails_gemfile_entry
if options.dev?
<<-GEMFILE.strip_heredoc
- gem 'rails', :path => '#{Rails::Generators::RAILS_DEV_PATH}'
- gem 'arel', :git => 'git://github.com/rails/arel.git'
- gem 'rack', :git => 'git://github.com/rack/rack.git'
+ gem 'rails', :path => '#{Rails::Generators::RAILS_DEV_PATH}'
GEMFILE
elsif options.edge?
<<-GEMFILE.strip_heredoc
- gem 'rails', :git => 'git://github.com/rails/rails.git'
- gem 'arel', :git => 'git://github.com/rails/arel.git'
- gem 'rack', :git => 'git://github.com/rack/rack.git'
+ gem 'rails', :git => 'git://github.com/rails/rails.git'
GEMFILE
else
<<-GEMFILE.strip_heredoc
gem 'rails', '#{Rails::VERSION::STRING}'
# Bundle edge Rails instead:
- # gem 'rails', :git => 'git://github.com/rails/rails.git'
- # gem 'arel', :git => 'git://github.com/rails/arel.git'
- # gem 'rack', :git => 'git://github.com/rack/rack.git'
+ # gem 'rails', :git => 'git://github.com/rails/rails.git'
GEMFILE
end
end
def gem_for_database
- # %w( mysql oracle postgresql sqlite3 frontbase ibm_db )
+ # %w( mysql oracle postgresql sqlite3 frontbase ibm_db jdbcmysql jdbcsqlite3 jdbcpostgresql )
case options[:database]
when "oracle" then "ruby-oci8"
when "postgresql" then "pg"
when "frontbase" then "ruby-frontbase"
when "mysql" then "mysql2"
+ when "jdbcmysql" then "activerecord-jdbcmysql-adapter"
+ when "jdbcsqlite3" then "activerecord-jdbcsqlite3-adapter"
+ when "jdbcpostgresql" then "activerecord-jdbcpostgresql-adapter"
else options[:database]
end
end
+ def gem_for_ruby_debugger
+ if RUBY_VERSION < "1.9.2"
+ "gem 'ruby-debug'"
+ else
+ "gem 'ruby-debug19', :require => 'ruby-debug'"
+ end
+ end
+
+ def gem_for_turn
+ unless RUBY_VERSION < "1.9.2"
+ <<-GEMFILE.strip_heredoc
+ group :test do
+ # Pretty printed test output
+ gem 'turn', :require => false
+ end
+ GEMFILE
+ end
+ end
+
+ def gem_for_javascript
+ "gem '#{options[:javascript]}-rails'" unless options[:skip_javascript]
+ 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?
@@ -174,6 +195,10 @@ module Rails
def empty_directory_with_gitkeep(destination, config = {})
empty_directory(destination, config)
+ git_keep(destination)
+ end
+
+ def git_keep(destination)
create_file("#{destination}/.gitkeep") unless options[:skip_git]
end