-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc8dc67
commit 5d55931
Showing
4 changed files
with
303 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails/generators/named_base' | ||
|
||
module Rails # :nodoc: | ||
module Generators # :nodoc: | ||
class JobGenerator < Rails::Generators::NamedBase # :nodoc: | ||
class_option :queue, type: :string, default: 'default', desc: 'The queue name for the generated job' | ||
|
||
class_option :parent, type: :string, default: 'ApplicationJob', desc: 'The parent class 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 parent_class_name | ||
options[:parent] | ||
end | ||
|
||
def file_name | ||
@file_name ||= super.sub(/_job\z/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 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.