Module: Models::Auditable::ClassMethods

Defined in:
app/concerns/models/auditable.rb

Overview

Class-level DSL for declaring skipped audit columns and reference metadata.

Instance Method Summary collapse

Instance Method Details

#audit_reference_data(*fields) ⇒ void

This method returns an undefined value.

Declares fields whose values are copied onto every version's
reference_data metadata — e.g. a foreign key which will not reappear
in all the changes.

Parameters:

  • fields (Array<Symbol, String>)

    method/attribute names to capture



68
69
70
# File 'app/concerns/models/auditable.rb', line 68

def audit_reference_data(*fields)
  self.reference_data = fields&.flatten
end

#skip_audit_for(*sk_columns) ⇒ void

This method returns an undefined value.

Excludes the given columns from versioning — merged into PaperTrail's
:skip and :ignore options.

PaperTrail resolves :skip / :ignore when has_paper_trail runs — that is,
inside included do, which fires BEFORE this class-body call. Recording the
columns in skipped_columns alone therefore never reached PaperTrail, so every
declaration here was silently inert (~2.7 GB of supposedly-skipped audit data
across 6 models by 2026-07). Merge them into the already-built options instead.

:skip keeps the column out of object / object_changes; :ignore stops a
change to it alone from cutting a version. Reassign rather than mutate — the
options are a class_attribute, so in-place edits would leak to sibling models.

Parameters:

  • sk_columns (Array<Symbol, String>)

    column names to skip



52
53
54
55
56
57
58
59
60
# File 'app/concerns/models/auditable.rb', line 52

def skip_audit_for(*sk_columns)
  self.skipped_columns = sk_columns&.flatten
  columns = Array(skipped_columns).map(&:to_s)

  self.paper_trail_options = paper_trail_options.merge(
    skip: paper_trail_options[:skip] | columns,
    ignore: paper_trail_options[:ignore] | columns
  )
end