Skip to content

Commit

Permalink
Merge pull request #945 from bullet-train-co/jeremy/audit-logs-super-…
Browse files Browse the repository at this point in the history
…scaffolding

Add a generator for AuditLogs
  • Loading branch information
jagthedrummer authored Nov 15, 2024
2 parents bd0f181 + 9605bd2 commit 577fe8b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ module SuperScaffolding
"action-models:targets-one" => "BulletTrain::ActionModels::Scaffolders::TargetsOneScaffolder",
"action-models:targets-one-parent" => "BulletTrain::ActionModels::Scaffolders::TargetsOneParentScaffolder",
"action-models:performs-export" => "BulletTrain::ActionModels::Scaffolders::PerformsExportScaffolder",
"action-models:performs-import" => "BulletTrain::ActionModels::Scaffolders::PerformsImportScaffolder"
"action-models:performs-import" => "BulletTrain::ActionModels::Scaffolders::PerformsImportScaffolder",
"audit-logs" => "BulletTrain::AuditLogs::Scaffolders::AuditLogScaffolder"
}

class Runner
Expand Down
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`.
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

0 comments on commit 577fe8b

Please sign in to comment.