-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #945 from bullet-train-co/jeremy/audit-logs-super-…
…scaffolding Add a generator for AuditLogs
- Loading branch information
Showing
3 changed files
with
50 additions
and
1 deletion.
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
22 changes: 22 additions & 0 deletions
22
bullet_train-super_scaffolding/lib/generators/super_scaffold/audit_logs/USAGE
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,22 @@ | ||
Description: | ||
Generate files needed to add an audit log to a model. | ||
|
||
Example: | ||
E.g. Add audit logs to Posts from a Team. | ||
rails generate super_scaffold:audit_logs Post Team name:text_field | ||
|
||
The attributes you specify will be added to the _version partial and used to show different versions of the model. | ||
|
||
This will create: | ||
db/migrate/20241115152914_add_project_to_activity_versions.rb | ||
app/views/account/projects/_version.html.erb'. | ||
And update: | ||
app/models/project.rb | ||
app/models/activity/version.rb | ||
app/views/account/projects/show.html.erb | ||
app/models/activity/version.rb | ||
config/routes.rb | ||
app/controllers/account/projects_controller.rb | ||
|
||
🏆 Protip: Commit your other changes before running Super Scaffolding so it's easy to undo if you (or we) make any mistakes. | ||
If you do that, you can reset to your last commit state by using `git checkout .` and `git clean -d -f`. |
26 changes: 26 additions & 0 deletions
26
..._train-super_scaffolding/lib/generators/super_scaffold/audit_logs/audit_logs_generator.rb
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,26 @@ | ||
require_relative "../super_scaffold_base" | ||
require "scaffolding/routes_file_manipulator" | ||
|
||
class AuditLogsGenerator < Rails::Generators::Base | ||
include SuperScaffoldBase | ||
|
||
source_root File.expand_path("templates", __dir__) | ||
|
||
namespace "super_scaffold:audit_logs" | ||
|
||
argument :target_model, type: :string | ||
argument :parent_model, type: :string | ||
argument :attributes, type: :array, banner: "attribute:type attribute:type" | ||
|
||
def generate | ||
if defined?(BulletTrain::AuditLogs) | ||
# We add the name of the specific super_scaffolding command that we want to | ||
# invoke to the beginning of the argument string. | ||
ARGV.unshift "audit-logs" | ||
BulletTrain::SuperScaffolding::Runner.new.run | ||
else | ||
puts "You must have AuditLogs installed if you want to use this generator.".red | ||
puts "Please refer to the documentation for more information: https://bullettrain.co/docs/audit-logs" | ||
end | ||
end | ||
end |