From 9a9fc01af08b5095de5b6f4f74ffd9dea7759500 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sat, 12 Mar 2016 15:00:55 +0900 Subject: generate ApplicationJob if it does not already exist ActiveJob jobs now inherit from ApplicationJob by default. However, when updating to Rails 5 from the old Rails, since there is a possibility that ApplicationJob does not exist. --- activejob/lib/rails/generators/job/job_generator.rb | 15 +++++++++++++++ .../lib/rails/generators/job/templates/application_job.rb | 4 ++++ 2 files changed, 19 insertions(+) create mode 100644 activejob/lib/rails/generators/job/templates/application_job.rb (limited to 'activejob') diff --git a/activejob/lib/rails/generators/job/job_generator.rb b/activejob/lib/rails/generators/job/job_generator.rb index 2115fb9f71..6e43e4a269 100644 --- a/activejob/lib/rails/generators/job/job_generator.rb +++ b/activejob/lib/rails/generators/job/job_generator.rb @@ -17,7 +17,22 @@ module Rails # :nodoc: def create_job_file template 'job.rb', File.join('app/jobs', class_path, "#{file_name}_job.rb") + + in_root do + if self.behavior == :invoke && !File.exist?(application_job_file_name) + template 'application_job.rb', application_job_file_name + end + end end + + private + def application_job_file_name + @application_job_file_name ||= if mountable_engine? + "app/jobs/#{namespaced_path}/application_job.rb" + else + 'app/jobs/application_job.rb' + end + end end end end diff --git a/activejob/lib/rails/generators/job/templates/application_job.rb b/activejob/lib/rails/generators/job/templates/application_job.rb new file mode 100644 index 0000000000..0b113b950e --- /dev/null +++ b/activejob/lib/rails/generators/job/templates/application_job.rb @@ -0,0 +1,4 @@ +<% module_namespacing do -%> +class ApplicationJob < ActiveJob::Base +end +<% end -%> -- cgit v1.2.3