forked from sidekiq/sidekiq
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
Showing
5 changed files
with
74 additions
and
0 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
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,9 @@ | ||
<% module_namespacing do -%> | ||
class <%= class_name %>Worker | ||
include Sidekiq::Worker | ||
|
||
def perform(*args) | ||
# Do something | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require 'rails_helper' | ||
<% module_namespacing do -%> | ||
RSpec.describe <%= class_name %>Worker, :type => :worker do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require_relative 'test_helper' | ||
<% module_namespacing do -%> | ||
class <%= class_name %>WorkerTest < MiniTest::Unit::TestCase | ||
def test_example | ||
skip "add some examples to (or delete) #{__FILE__}" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require 'rails/generators/named_base' | ||
|
||
module Sidekiq | ||
module Generators # :nodoc: | ||
class WorkerGenerator < ::Rails::Generators::NamedBase # :nodoc: | ||
desc 'This generator creates a sidekiq worker file at app/workers' | ||
|
||
check_class_collision suffix: 'Worker' | ||
|
||
def self.default_generator_root | ||
File.dirname(__FILE__) | ||
end | ||
|
||
def create_worker_file | ||
template 'worker.rb.erb', File.join('app/workers', class_path, "#{file_name}_worker.rb") | ||
end | ||
|
||
def create_test_file | ||
if defined?(RSpec) | ||
create_worker_spec | ||
else | ||
create_worker_test | ||
end | ||
end | ||
|
||
private | ||
|
||
def create_worker_spec | ||
template_file = File.join( | ||
'spec/workers', | ||
class_path, | ||
"#{file_name}_spec.rb" | ||
) | ||
template 'worker_spec.rb.erb', template_file | ||
end | ||
|
||
def create_worker_test | ||
template_file = File.join( | ||
'test/workers', | ||
class_path, | ||
"#{file_name}_test.rb" | ||
) | ||
template 'worker_test.rb.erb', template_file | ||
end | ||
|
||
|
||
end | ||
end | ||
end |