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

45 lines
1.1 KiB
Ruby
Raw Normal View History

2017-07-09 13:49:52 -04:00
# frozen_string_literal: true
require "rails/generators/named_base"
2014-06-29 11:59:38 -04:00
2015-04-29 21:44:37 -04:00
module Rails # :nodoc:
2014-06-29 11:59:38 -04:00
module Generators # :nodoc:
class JobGenerator < Rails::Generators::NamedBase # :nodoc:
desc "This generator creates an active job file at app/jobs"
2014-06-29 11:59:38 -04:00
class_option :queue, type: :string, default: "default", desc: "The queue name for the generated job"
2014-06-29 11:59:38 -04:00
check_class_collision suffix: "Job"
hook_for :test_framework
2014-06-29 11:59:38 -04:00
def self.default_generator_root
__dir__
2014-06-29 11:59:38 -04:00
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
2014-06-29 11:59:38 -04:00
end
private
2018-04-21 23:09:04 -04:00
def file_name
@_file_name ||= super.gsub(/_job/i, "")
end
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
2014-06-29 11:59:38 -04:00
end
end
end