-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
abstract rails/add_application_job snippet
- Loading branch information
Showing
4 changed files
with
73 additions
and
25 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,32 @@ | ||
Synvert::Rewriter.new 'rails', 'add_application_job' do | ||
description <<-EOF | ||
It adds app/models/application_job.rb file and replaces ActiveJob::Base with ApplicationJob in model files. | ||
class PostJob < ActiveJob::Base | ||
end | ||
=> | ||
class PostJob < ApplicationJob | ||
end | ||
EOF | ||
|
||
# adds file app/models/application_job.rb | ||
add_file 'app/jobs/application_job.rb', <<~EOS | ||
class ApplicationJob < ActiveJob::Base | ||
end | ||
EOS | ||
|
||
within_files 'app/jobs/**/*.rb' do | ||
# class PostJob < ActiveJob::Base | ||
# end | ||
# => | ||
# class PostJob < ApplicationJob | ||
# end | ||
with_node type: 'class', name: { not: 'ApplicationJob' }, parent_class: 'ActiveJob::Base' do | ||
goto_node :parent_class do | ||
replace_with 'ApplicationJob' | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe 'Add ApplicationJob' do | ||
let(:rewriter_name) { 'rails/add_application_job' } | ||
|
||
context 'add application_job' do | ||
let(:fake_file_path) { 'app/jobs/application_job.rb' } | ||
let(:test_content) { nil } | ||
let(:test_rewritten_content) { | ||
<<~EOS | ||
class ApplicationJob < ActiveJob::Base | ||
end | ||
EOS | ||
} | ||
|
||
include_examples 'convertable' | ||
end | ||
|
||
context 'rename ActiveJob::Base' do | ||
let(:fake_file_path) { 'app/jobs/post_job.rb' } | ||
let(:test_content) { | ||
<<~EOS | ||
class PostJob < ActiveJob::Base | ||
end | ||
EOS | ||
} | ||
let(:test_rewritten_content) { | ||
<<~EOS | ||
class PostJob < ApplicationJob | ||
end | ||
EOS | ||
} | ||
|
||
include_examples 'convertable' | ||
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