-
-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: generators can run without prior migrations (#2861)
Co-authored-by: Paul Bob <[email protected]> Co-authored-by: Paul Bob <[email protected]>
- Loading branch information
1 parent
ba598ff
commit 4a85c71
Showing
3 changed files
with
339 additions
and
278 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,36 @@ | ||
require_relative "base_generator" | ||
|
||
module Generators | ||
module Avo | ||
class AllResourcesGenerator < BaseGenerator | ||
namespace "avo:all_resources" | ||
|
||
def task | ||
# Rails.application.eager_load! | ||
# get all models | ||
models = fetch_models | ||
models.delete("ApplicationRecord") | ||
|
||
models | ||
.each do |model| | ||
Rails::Generators.invoke "avo:resource", [model.underscore], {} | ||
rescue => e | ||
puts "Error: #{e.message}" | ||
end | ||
end | ||
|
||
no_tasks do | ||
def fetch_models | ||
model_files = Dir[Rails.root.join("app/models/**/*.rb")] | ||
model_files.map do |file| | ||
model_name = file.sub(Rails.root.join("app/models/").to_s, "").sub(".rb", "") | ||
model_name.camelize.constantize | ||
model_name.camelize | ||
rescue NameError | ||
nil | ||
end.compact | ||
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
Oops, something went wrong.