lib/rails/generators/app_base.rb in railties-7.0.0 vs lib/rails/generators/app_base.rb in railties-7.0.1

- old
+ new

@@ -106,20 +106,22 @@ super end private def gemfile_entries # :doc: - [rails_gemfile_entry, - asset_pipeline_gemfile_entry, - database_gemfile_entry, - web_server_gemfile_entry, - javascript_gemfile_entry, - hotwire_gemfile_entry, - css_gemfile_entry, - jbuilder_gemfile_entry, - psych_gemfile_entry, - cable_gemfile_entry].flatten.find_all(&@gem_filter) + [ + rails_gemfile_entry, + asset_pipeline_gemfile_entry, + database_gemfile_entry, + web_server_gemfile_entry, + javascript_gemfile_entry, + hotwire_gemfile_entry, + css_gemfile_entry, + jbuilder_gemfile_entry, + psych_gemfile_entry, + cable_gemfile_entry, + ].flatten.compact.select(&@gem_filter) end def builder # :doc: @builder ||= begin builder_class = get_builder_class @@ -157,30 +159,29 @@ options[:template] end end def database_gemfile_entry # :doc: - return [] if options[:skip_active_record] + return if options[:skip_active_record] + gem_name, gem_version = gem_for_database GemfileEntry.version gem_name, gem_version, "Use #{options[:database]} as the database for Active Record" end def web_server_gemfile_entry # :doc: GemfileEntry.new "puma", "~> 5.0", "Use the Puma web server [https://github.com/puma/puma]" end def asset_pipeline_gemfile_entry - return [] if options[:skip_asset_pipeline] + return if options[:skip_asset_pipeline] if options[:asset_pipeline] == "sprockets" GemfileEntry.floats "sprockets-rails", "The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]" elsif options[:asset_pipeline] == "propshaft" GemfileEntry.floats "propshaft", "The modern asset pipeline for Rails [https://github.com/rails/propshaft]" - else - [] end end def include_all_railties? # :doc: [ @@ -262,24 +263,17 @@ def self.path(name, path, comment = nil) new(name, nil, comment, path: path) end - def version - version = super - - if version.is_a?(Array) - version.join('", "') - else - version - end - end - def to_s - [ ("# #{comment}\n" if comment), - ("# " if commented_out), "gem \"#{name}\"", (", \"#{version}\"" if version), - *options.map { |key, val| ", #{key}: #{val.inspect}" } + [ + (comment.gsub(/^/, "# ").chomp + "\n" if comment), + ("# " if commented_out), + "gem \"#{name}\"", + *Array(version).map { |constraint| ", \"#{constraint}\"" }, + *options.map { |key, value| ", #{key}: #{value.inspect}" }, ].compact.join end end def rails_prerelease? @@ -312,26 +306,26 @@ ["~> #{patch}", ">= #{gem_version}"] end end def jbuilder_gemfile_entry - return [] if options[:skip_jbuilder] + return if options[:skip_jbuilder] GemfileEntry.new "jbuilder", nil, "Build JSON APIs with ease [https://github.com/rails/jbuilder]", {}, options[:api] end def javascript_gemfile_entry - return [] if options[:skip_javascript] + return if options[:skip_javascript] if adjusted_javascript_option == "importmap" GemfileEntry.floats "importmap-rails", "Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]" else GemfileEntry.floats "jsbundling-rails", "Bundle and transpile JavaScript [https://github.com/rails/jsbundling-rails]" end end def hotwire_gemfile_entry - return [] if options[:skip_javascript] || options[:skip_hotwire] + return if options[:skip_javascript] || options[:skip_hotwire] turbo_rails_entry = GemfileEntry.floats "turbo-rails", "Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]" stimulus_rails_entry = @@ -353,32 +347,31 @@ options[:javascript] end end def css_gemfile_entry - return [] unless options[:css] + return unless options[:css] if !using_node? && options[:css] == "tailwind" GemfileEntry.floats "tailwindcss-rails", "Use Tailwind CSS [https://github.com/rails/tailwindcss-rails]" else GemfileEntry.floats "cssbundling-rails", "Bundle and process CSS [https://github.com/rails/cssbundling-rails]" end end def psych_gemfile_entry - return [] unless defined?(Rubinius) + return unless defined?(Rubinius) 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 cable_gemfile_entry - return [] if options[:skip_action_cable] + return if options[:skip_action_cable] + comment = "Use Redis adapter to run Action Cable in production" - gems = [] - gems << GemfileEntry.new("redis", "~> 4.0", comment, {}, true) - gems + GemfileEntry.new("redis", "~> 4.0", comment, {}, true) end def bundle_command(command, env = {}) say_status :run, "bundle #{command}"