1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activejob/lib/rails/generators/job/job_generator.rb
bogdanvlviv 40bdbce191
Define path with __dir__
".. with __dir__ we can restore order in the Universe." - by @fxn

Related to 5b8738c2df
2017-05-23 00:53:51 +03:00

38 lines
1 KiB
Ruby

require "rails/generators/named_base"
module Rails # :nodoc:
module Generators # :nodoc:
class JobGenerator < Rails::Generators::NamedBase # :nodoc:
desc "This generator creates an active job file at app/jobs"
class_option :queue, type: :string, default: "default", desc: "The queue name for the generated job"
check_class_collision suffix: "Job"
hook_for :test_framework
def self.default_generator_root
__dir__
end
def create_job_file
template "job.rb", File.join("app/jobs", class_path, "#{file_name}_job.rb")
in_root do
if 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