Module: Whodunit
- Defined in:
- lib/whodunit.rb,
lib/whodunit/current.rb,
lib/whodunit/railtie.rb,
lib/whodunit/version.rb,
lib/whodunit/generator.rb,
lib/whodunit/stampable.rb,
lib/whodunit/migration_helpers.rb,
lib/whodunit/controller_methods.rb,
lib/whodunit/table_definition_extension.rb
Overview
Lightweight creator/updater/deleter tracking for ActiveRecord models.
Whodunit provides simple auditing by tracking who created, updated, and deleted ActiveRecord models. It features smart soft-delete detection and zero performance overhead.
Defined Under Namespace
Modules: ControllerMethods, MigrationHelpers, Stampable, TableDefinitionExtension Classes: Current, Error, Generator, Railtie
Constant Summary collapse
- VERSION =
"0.2.0"
Configuration collapse
-
#auto_inject_whodunit_stamps ⇒ Boolean
Whether to automatically add whodunit_stamps to create_table migrations (default: true).
-
#creator_column ⇒ Symbol
The column name for tracking who created the record (default: :creator_id).
-
#deleter_column ⇒ Symbol
The column name for tracking who deleted the record (default: :deleter_id).
-
#soft_delete_column ⇒ Symbol?
The column name used for soft-delete timestamps (default: nil) Set to a column name to enable soft-delete support (e.g., :deleted_at, :discarded_at) Set to nil to disable soft-delete support entirely.
-
#updater_column ⇒ Symbol
The column name for tracking who updated the record (default: :updater_id).
-
#user_class ⇒ String
The class name of the user model (default: “User”).
Data Type Configuration collapse
-
.configure {|self| ... } ⇒ void
Configure Whodunit settings.
-
.user_class_name ⇒ String
Get the user class name as a string.
-
#column_data_type ⇒ Symbol
The default data type for stamp columns (default: :bigint).
-
#creator_column_type ⇒ Symbol?
Specific data type for creator column (overrides column_data_type if set).
-
#deleter_column_type ⇒ Symbol?
Specific data type for deleter column (overrides column_data_type if set).
-
#updater_column_type ⇒ Symbol?
Specific data type for updater column (overrides column_data_type if set).
Data Type Helpers collapse
-
.creator_data_type ⇒ Symbol
Get the data type for the creator column.
-
.creator_enabled? ⇒ Boolean
Check if creator column is enabled.
-
.deleter_data_type ⇒ Symbol
Get the data type for the deleter column.
-
.deleter_enabled? ⇒ Boolean
Check if deleter column is enabled.
-
.soft_delete_enabled? ⇒ Boolean
Check if soft-delete is enabled.
-
.updater_data_type ⇒ Symbol
Get the data type for the updater column.
-
.updater_enabled? ⇒ Boolean
Check if updater column is enabled.
-
.validate_column_configuration! ⇒ Object
Validate that column configuration is valid.
Class Method Details
.configure {|self| ... } ⇒ void
This method returns an undefined value.
Configure Whodunit settings
98 99 100 101 |
# File 'lib/whodunit.rb', line 98 def self.configure yield self validate_column_configuration! end |
.creator_data_type ⇒ Symbol
Get the data type for the creator column
114 115 116 |
# File 'lib/whodunit.rb', line 114 def self.creator_data_type creator_column_type || column_data_type end |
.creator_enabled? ⇒ Boolean
Check if creator column is enabled
138 139 140 |
# File 'lib/whodunit.rb', line 138 def self.creator_enabled? !creator_column.nil? end |
.deleter_data_type ⇒ Symbol
Get the data type for the deleter column
126 127 128 |
# File 'lib/whodunit.rb', line 126 def self.deleter_data_type deleter_column_type || column_data_type end |
.deleter_enabled? ⇒ Boolean
Check if deleter column is enabled
150 151 152 |
# File 'lib/whodunit.rb', line 150 def self.deleter_enabled? !deleter_column.nil? end |
.soft_delete_enabled? ⇒ Boolean
Check if soft-delete is enabled
132 133 134 |
# File 'lib/whodunit.rb', line 132 def self.soft_delete_enabled? !soft_delete_column.nil? end |
.updater_data_type ⇒ Symbol
Get the data type for the updater column
120 121 122 |
# File 'lib/whodunit.rb', line 120 def self.updater_data_type updater_column_type || column_data_type end |
.updater_enabled? ⇒ Boolean
Check if updater column is enabled
144 145 146 |
# File 'lib/whodunit.rb', line 144 def self.updater_enabled? !updater_column.nil? end |
.user_class_name ⇒ String
Get the user class name as a string
106 107 108 |
# File 'lib/whodunit.rb', line 106 def self.user_class_name user_class.to_s end |
.validate_column_configuration! ⇒ Object
Validate that column configuration is valid
156 157 158 159 160 161 162 |
# File 'lib/whodunit.rb', line 156 def self.validate_column_configuration! return if creator_enabled? || updater_enabled? raise Whodunit::Error, "At least one of creator_column or updater_column must be configured (not nil). " \ "Setting both to nil would disable all stamping functionality." end |
Instance Method Details
#auto_inject_whodunit_stamps ⇒ Boolean
Whether to automatically add whodunit_stamps to create_table migrations (default: true)
66 |
# File 'lib/whodunit.rb', line 66 mattr_accessor :auto_inject_whodunit_stamps, default: true |
#column_data_type ⇒ Symbol
The default data type for stamp columns (default: :bigint)
72 |
# File 'lib/whodunit.rb', line 72 mattr_accessor :column_data_type, default: :bigint |
#creator_column ⇒ Symbol
The column name for tracking who created the record (default: :creator_id)
48 |
# File 'lib/whodunit.rb', line 48 mattr_accessor :creator_column, default: :creator_id |
#creator_column_type ⇒ Symbol?
Specific data type for creator column (overrides column_data_type if set)
76 |
# File 'lib/whodunit.rb', line 76 mattr_accessor :creator_column_type, default: nil |
#deleter_column ⇒ Symbol
The column name for tracking who deleted the record (default: :deleter_id)
56 |
# File 'lib/whodunit.rb', line 56 mattr_accessor :deleter_column, default: :deleter_id |
#deleter_column_type ⇒ Symbol?
Specific data type for deleter column (overrides column_data_type if set)
84 |
# File 'lib/whodunit.rb', line 84 mattr_accessor :deleter_column_type, default: nil |
#soft_delete_column ⇒ Symbol?
The column name used for soft-delete timestamps (default: nil) Set to a column name to enable soft-delete support (e.g., :deleted_at, :discarded_at) Set to nil to disable soft-delete support entirely
62 |
# File 'lib/whodunit.rb', line 62 mattr_accessor :soft_delete_column, default: nil |
#updater_column ⇒ Symbol
The column name for tracking who updated the record (default: :updater_id)
52 |
# File 'lib/whodunit.rb', line 52 mattr_accessor :updater_column, default: :updater_id |
#updater_column_type ⇒ Symbol?
Specific data type for updater column (overrides column_data_type if set)
80 |
# File 'lib/whodunit.rb', line 80 mattr_accessor :updater_column_type, default: nil |
#user_class ⇒ String
The class name of the user model (default: “User”)
44 |
# File 'lib/whodunit.rb', line 44 mattr_accessor :user_class, default: "User" |