-
-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add necessary files to make the [plugin][] an [engine][], which automatically loads Rake tasks located in `lib/tasks`. This means when the `suspenders` gem is installed, the consumer can run `bundle exec rake suspenders:rake`, and any future tasks. Because `suspenders:lint` and `suspenders:advisories` may not necessarily have been invoked, we need to check if those gems are installed. [plugin]: https://guides.rubyonrails.org/plugins.html [engine]: https://guides.rubyonrails.org/engines.html To Do - [ ] RSpec - [ ] Do we need to require bundler-audit in the Rakefile Co-authored-by: Mike Burns <[email protected]>
- Loading branch information
1 parent
fe5fc93
commit 34fb28a
Showing
8 changed files
with
88 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
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,14 @@ | ||
module Suspenders | ||
module Generators | ||
class RakeGenerator < Rails::Generators::Base | ||
source_root File.expand_path("../../templates/rake", __FILE__) | ||
desc(<<~TEXT) | ||
Configures the default Rake task to audit and lint the codebase with `bundler-audit` and `standard`. | ||
TEXT | ||
|
||
def configure_default_rake_task | ||
append_to_file "Rakefile", %(task default: "suspenders:rake") | ||
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,5 @@ | ||
module Suspenders | ||
class Engine < ::Rails::Engine | ||
isolate_namespace Suspenders | ||
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,12 @@ | ||
namespace :suspenders do | ||
desc "Default task for Suspenders" | ||
task :rake do | ||
if Bundler.rubygems.find_name("bundler-audit").any? | ||
Rake::Task[:"bundle:audit"].invoke | ||
end | ||
|
||
if Bundler.rubygems.find_name("standard").any? | ||
Rake::Task[:standard].invoke | ||
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,43 @@ | ||
require "test_helper" | ||
require "generators/suspenders/rake_generator" | ||
|
||
module Suspenders | ||
module Generators | ||
class RakeGeneratorTest < Rails::Generators::TestCase | ||
include Suspenders::TestHelpers | ||
|
||
tests Suspenders::Generators::RakeGenerator | ||
destination Rails.root | ||
setup :prepare_destination | ||
teardown :restore_destination | ||
|
||
test "modifies existing Rakefile" do | ||
run_generator | ||
|
||
assert_file app_root("Rakefile") do |file| | ||
assert_match /task default: "suspenders:rake"/, file | ||
end | ||
end | ||
|
||
test "generator has a description" do | ||
description = <<~TEXT | ||
Configures the default Rake task to audit and lint the codebase with `bundler-audit` and `standard`. | ||
TEXT | ||
|
||
assert_equal description, generator_class.desc | ||
end | ||
|
||
private | ||
|
||
def prepare_destination | ||
touch "Gemfile" | ||
backup_file "Rakefile" | ||
end | ||
|
||
def restore_destination | ||
remove_file_if_exists "Gemfile" | ||
restore_file "Rakefile" | ||
end | ||
end | ||
end | ||
end |