lib/rails/generators/app_base.rb in railties-4.1.16 vs lib/rails/generators/app_base.rb in railties-4.2.0.beta1
- old
+ new
@@ -39,10 +39,13 @@
desc: 'Skip source control .keep files'
class_option :skip_active_record, type: :boolean, aliases: '-O', default: false,
desc: 'Skip Active Record files'
+ class_option :skip_gems, type: :array, default: [],
+ desc: 'Skip the provided gems files'
+
class_option :skip_action_view, type: :boolean, aliases: '-V', default: false,
desc: 'Skip Action View files'
class_option :skip_sprockets, type: :boolean, aliases: '-S', default: false,
desc: 'Skip Sprockets files'
@@ -77,12 +80,11 @@
class_option :help, type: :boolean, aliases: '-h', group: :rails,
desc: 'Show this help message and quit'
end
def initialize(*args)
- @original_wd = Dir.pwd
- @gem_filter = lambda { |gem| true }
+ @gem_filter = lambda { |gem| !options[:skip_gems].include?(gem.name) }
@extra_entries = []
super
convert_database_option_for_jruby
end
@@ -103,19 +105,18 @@
end
self
end
def gemfile_entries
- [ rails_gemfile_entry,
- database_gemfile_entry,
- assets_gemfile_entry,
- javascript_gemfile_entry,
- jbuilder_gemfile_entry,
- sdoc_gemfile_entry,
- spring_gemfile_entry,
- mime_type_gemfile_entry,
- @extra_entries].flatten.find_all(&@gem_filter)
+ [rails_gemfile_entry,
+ database_gemfile_entry,
+ assets_gemfile_entry,
+ javascript_gemfile_entry,
+ jbuilder_gemfile_entry,
+ sdoc_gemfile_entry,
+ psych_gemfile_entry,
+ @extra_entries].flatten.find_all(&@gem_filter)
end
def add_gem_entry_filter
@gem_filter = lambda { |next_filter, entry|
yield(entry) && next_filter.call(entry)
@@ -159,12 +160,11 @@
end
end
def database_gemfile_entry
return [] if options[:skip_active_record]
- gem_name, gem_version = gem_for_database
- GemfileEntry.version gem_name, gem_version,
+ GemfileEntry.version gem_for_database, nil,
"Use #{options[:database]} as the database for Active Record"
end
def include_all_railties?
!options[:skip_active_record] && !options[:skip_action_view] && !options[:skip_test_unit] && !options[:skip_sprockets]
@@ -172,72 +172,57 @@
def comment_if(value)
options[value] ? '# ' : ''
end
+ def sqlite3?
+ !options[:skip_active_record] && options[:database] == 'sqlite3'
+ end
+
class GemfileEntry < Struct.new(:name, :version, :comment, :options, :commented_out)
def initialize(name, version, comment, options = {}, commented_out = false)
super
end
- def self.github(name, github, branch = nil, comment = nil)
- if branch
- new(name, nil, comment, github: github, branch: branch)
- else
- new(name, nil, comment, github: github)
- end
+ def self.github(name, github, comment = nil)
+ new(name, nil, comment, github: github)
end
def self.version(name, version, comment = nil)
new(name, version, comment)
end
def self.path(name, path, comment = nil)
new(name, nil, comment, path: path)
end
-
- def padding(max_width)
- ' ' * (max_width - name.length + 2)
- end
-
- def version
- version = super
-
- if version.is_a?(Array)
- version.join("', '")
- else
- version
- end
- end
end
def rails_gemfile_entry
if options.dev?
- [GemfileEntry.path('rails', Rails::Generators::RAILS_DEV_PATH),
- GemfileEntry.github('arel', 'rails/arel', '5-0-stable')]
+ [GemfileEntry.path('rails', Rails::Generators::RAILS_DEV_PATH)]
elsif options.edge?
- [GemfileEntry.github('rails', 'rails/rails', '4-1-stable')]
+ [GemfileEntry.github('rails', 'rails/rails')]
else
[GemfileEntry.version('rails',
Rails::VERSION::STRING,
"Bundle edge Rails instead: gem 'rails', github: 'rails/rails'")]
end
end
def gem_for_database
# %w( mysql oracle postgresql sqlite3 frontbase ibm_db sqlserver jdbcmysql jdbcsqlite3 jdbcpostgresql )
case options[:database]
- when "oracle" then ["ruby-oci8", nil]
- when "postgresql" then ["pg", ["~> 0.11"]]
- when "frontbase" then ["ruby-frontbase", nil]
- when "mysql" then ["mysql2", ["~> 0.3.13"]]
- when "sqlserver" then ["activerecord-sqlserver-adapter", nil]
- when "jdbcmysql" then ["activerecord-jdbcmysql-adapter", nil]
- when "jdbcsqlite3" then ["activerecord-jdbcsqlite3-adapter", nil]
- when "jdbcpostgresql" then ["activerecord-jdbcpostgresql-adapter", nil]
- when "jdbc" then ["activerecord-jdbc-adapter", nil]
- else [options[:database], nil]
+ when "oracle" then "ruby-oci8"
+ when "postgresql" then "pg"
+ when "frontbase" then "ruby-frontbase"
+ when "mysql" then "mysql2"
+ when "sqlserver" then "activerecord-sqlserver-adapter"
+ when "jdbcmysql" then "activerecord-jdbcmysql-adapter"
+ when "jdbcsqlite3" then "activerecord-jdbcsqlite3-adapter"
+ when "jdbcpostgresql" then "activerecord-jdbcpostgresql-adapter"
+ when "jdbc" then "activerecord-jdbc-adapter"
+ else options[:database]
end
end
def convert_database_option_for_jruby
if defined?(JRUBY_VERSION)
@@ -251,18 +236,27 @@
end
def assets_gemfile_entry
return [] if options[:skip_sprockets]
- [
- GemfileEntry.version('sass-rails',
- '~> 4.0.3',
- 'Use SCSS for stylesheets'),
- GemfileEntry.version('uglifier',
- '>= 1.3.0',
- 'Use Uglifier as compressor for JavaScript assets')
- ]
+ gems = []
+ if options.dev? || options.edge?
+ gems << GemfileEntry.github('sprockets-rails', 'rails/sprockets-rails',
+ 'Use edge version of sprockets-rails')
+ gems << GemfileEntry.github('sass-rails', 'rails/sass-rails',
+ 'Use SCSS for stylesheets')
+ else
+ gems << GemfileEntry.version('sass-rails',
+ '~> 5.0.0.beta1',
+ 'Use SCSS for stylesheets')
+ end
+
+ gems << GemfileEntry.version('uglifier',
+ '>= 1.3.0',
+ 'Use Uglifier as compressor for JavaScript assets')
+
+ gems
end
def jbuilder_gemfile_entry
comment = 'Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder'
GemfileEntry.version('jbuilder', '~> 2.0', comment)
@@ -274,11 +268,11 @@
end
def coffee_gemfile_entry
comment = 'Use CoffeeScript for .js.coffee assets and views'
if options.dev? || options.edge?
- GemfileEntry.github 'coffee-rails', 'rails/coffee-rails', nil, comment
+ GemfileEntry.github 'coffee-rails', 'rails/coffee-rails', comment
else
GemfileEntry.version 'coffee-rails', '~> 4.0.0', comment
end
end
@@ -295,27 +289,23 @@
gems
end
end
def javascript_runtime_gemfile_entry
- comment = 'See https://github.com/rails/execjs#readme for more supported runtimes'
+ comment = 'See https://github.com/sstephenson/execjs#readme for more supported runtimes'
if defined?(JRUBY_VERSION)
GemfileEntry.version 'therubyrhino', nil, comment
else
GemfileEntry.new 'therubyracer', nil, comment, { platforms: :ruby }, true
end
end
- def spring_gemfile_entry
- return [] unless spring_install?
- comment = 'Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring'
- GemfileEntry.new('spring', nil, comment, group: :development)
- end
+ def psych_gemfile_entry
+ return [] unless defined?(Rubinius)
- def mime_type_gemfile_entry
- return [] unless RUBY_VERSION < '2'
-
- GemfileEntry.new('mime-types', '< 3', nil, require: false)
+ comment = 'Use Psych as the YAML engine, instead of Syck, so serialized ' \
+ 'data can be read safely from different rubies (see http://git.io/uuLVag)'
+ GemfileEntry.new('psych', '~> 2.0', comment, platforms: :rbx)
end
def bundle_command(command)
say_status :run, "bundle #{command}"