Class: Whodunit::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/whodunit/generator.rb,
lib/whodunit/generator/application_record_integration.rb

Overview

Generator for creating Whodunit configuration files

Since:

  • 0.1.0

Defined Under Namespace

Modules: ApplicationRecordIntegration

Constant Summary collapse

INITIALIZER_CONTENT =

Since:

  • 0.1.0

<<~RUBY
  # frozen_string_literal: true

  # Whodunit configuration
  # This file was generated by `whodunit install` command.
  # Uncomment and modify the options you want to customize.

  # Whodunit.configure do |config|
  #   # User model configuration
  #   # Specify which model represents users in your application
  #   config.user_class = 'Account'             # Default: 'User'
  #                                             # Use 'Account', 'Admin', etc. if your user model has a different name
  #
  #   # Column name configuration
  #   # Customize the names of the tracking columns in your database
  #   config.creator_column = :created_by_id    # Default: :creator_id
  #                                             # Column that stores who created the record
  #   config.updater_column = :updated_by_id    # Default: :updater_id
  #                                             # Column that stores who last updated the record
  #   config.deleter_column = :deleted_by_id    # Default: :deleter_id
  #                                             # Column that stores who deleted the record (soft-delete only)
  #
  #   # Soft-delete integration
  #   # Enable tracking of who deleted records when using soft-delete gems
  #   config.soft_delete_column = :discarded_at # Default: nil (disabled)
  #                                             # Set to :deleted_at for Paranoia gem
  #                                             # Set to :discarded_at for Discard gem
  #                                             # Set to your custom soft-delete column name
  #                                             # Set to nil to disable soft-delete tracking
  #
  #   # Migration auto-injection
  #   # Control whether whodunit stamps are automatically added to new migrations
  #   config.auto_inject_whodunit_stamps = false # Default: true
  #                                               # When true, automatically adds t.whodunit_stamps to create_table migrations
  #                                               # When false, you must manually add t.whodunit_stamps to your migrations
  #
  #   # Column data type configuration
  #   # Configure what data types to use for the tracking columns
  #   config.column_data_type = :integer       # Default: :bigint
  #                                            # Global default for all stamp columns
  #                                            # Common options: :bigint, :integer, :string, :uuid
  #
  #   # Individual column type overrides
  #   # Override the data type for specific columns (takes precedence over column_data_type)
  #   config.creator_column_type = :string     # Default: nil (uses column_data_type)
  #                                            # Useful if your user IDs are strings or UUIDs
  #   config.updater_column_type = :uuid       # Default: nil (uses column_data_type)
  #                                            # Set to match your user model's primary key type
  #   config.deleter_column_type = :integer    # Default: nil (uses column_data_type)
  #                                            # Only used when soft_delete_column is configured
  # end
RUBY

Class Method Summary collapse

Class Method Details

.help_messageObject

Since:

  • 0.1.0



119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/whodunit/generator.rb', line 119

def self.help_message
  <<~HELP
    Whodunit - Lightweight creator/updater/deleter tracking for ActiveRecord

    Usage:
      whodunit install    Generate config/initializers/whodunit.rb
      whodunit help       Show this help message

    Examples:
      whodunit install    # Creates config/initializers/whodunit.rb with sample configuration

    For more information, visit: https://github.com/kanutocd/whodunit
  HELP
end

.install_initializerObject

Since:

  • 0.1.0



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/whodunit/generator.rb', line 62

def self.install_initializer
  config_dir = "config/initializers"
  config_file = File.join(config_dir, "whodunit.rb")

  validate_rails_application!
  ensure_config_directory_exists!(config_dir)
  handle_existing_file!(config_file)
  create_initializer_file!(config_file)
  ApplicationRecordIntegration.handle_application_record_integration!
  show_success_message(config_file)
end