diff options
Diffstat (limited to 'railties/lib/rails')
-rw-r--r-- | railties/lib/rails/app_updater.rb | 31 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/app/app_generator.rb | 2 | ||||
-rw-r--r-- | railties/lib/rails/tasks/framework.rake | 27 |
3 files changed, 37 insertions, 23 deletions
diff --git a/railties/lib/rails/app_updater.rb b/railties/lib/rails/app_updater.rb new file mode 100644 index 0000000000..e53d1cf093 --- /dev/null +++ b/railties/lib/rails/app_updater.rb @@ -0,0 +1,31 @@ +require "rails/generators" +require "rails/generators/rails/app/app_generator" + +module Rails + class AppUpdater # :nodoc: + class << self + def invoke_from_app_generator(method) + app_generator.send(method) + end + + def app_generator + @app_generator ||= begin + gen = Rails::Generators::AppGenerator.new ["rails"], generator_options, destination_root: Rails.root + File.exist?(Rails.root.join("config", "application.rb")) ? gen.send(:app_const) : gen.send(:valid_const?) + gen + end + end + + private + def generator_options + options = { api: !!Rails.application.config.api_only, update: true } + options[:skip_active_record] = !defined?(ActiveRecord::Railtie) + options[:skip_action_mailer] = !defined?(ActionMailer::Railtie) + options[:skip_action_cable] = !defined?(ActionCable::Engine) + options[:skip_sprockets] = !defined?(Sprockets::Railtie) + options[:skip_puma] = !defined?(Puma) + options + end + end + end +end diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 7614e6304b..7a59f106e3 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -128,7 +128,7 @@ module Rails gsub_file "config/initializers/cookies_serializer.rb", /json(?!,)/, "marshal" end - unless action_cable_config_exist + if !options[:skip_action_cable] && !action_cable_config_exist template "config/cable.yml" end diff --git a/railties/lib/rails/tasks/framework.rake b/railties/lib/rails/tasks/framework.rake index f7e8f4f340..6c6e86d78d 100644 --- a/railties/lib/rails/tasks/framework.rake +++ b/railties/lib/rails/tasks/framework.rake @@ -36,38 +36,21 @@ namespace :app do end namespace :update do - class RailsUpdate - def self.invoke_from_app_generator(method) - app_generator.send(method) - end - - def self.app_generator - @app_generator ||= begin - require_relative "../generators" - require_relative "../generators/rails/app/app_generator" - gen = Rails::Generators::AppGenerator.new ["rails"], - { api: !!Rails.application.config.api_only, update: true }, - destination_root: Rails.root - File.exist?(Rails.root.join("config", "application.rb")) ? - gen.send(:app_const) : gen.send(:valid_const?) - gen - end - end - end + require_relative "../app_updater" # desc "Update config/boot.rb from your current rails install" task :configs do - RailsUpdate.invoke_from_app_generator :create_boot_file - RailsUpdate.invoke_from_app_generator :update_config_files + Rails::AppUpdater.invoke_from_app_generator :create_boot_file + Rails::AppUpdater.invoke_from_app_generator :update_config_files end # desc "Adds new executables to the application bin/ directory" task :bin do - RailsUpdate.invoke_from_app_generator :update_bin_files + Rails::AppUpdater.invoke_from_app_generator :update_bin_files end task :upgrade_guide_info do - RailsUpdate.invoke_from_app_generator :display_upgrade_guide_info + Rails::AppUpdater.invoke_from_app_generator :display_upgrade_guide_info end end end |