Module: Journaled::AuditLog

Extended by:
ActiveSupport::Concern
Defined in:
lib/journaled/audit_log.rb,
app/models/journaled/audit_log/event.rb

Defined Under Namespace

Modules: BlockedClassMethods, BlockedMethods Classes: Config, Event

Constant Summary collapse

DEFAULT_EXCLUDED_CLASSES =
if Gem::Version.new(Rails.version) < Gem::Version.new('7.1')
  %w(
    Delayed::Job
    PaperTrail::Version
    ActiveStorage::Attachment
    ActiveStorage::Blob
    ActiveRecord::InternalMetadata
    ActiveRecord::SchemaMigration
  )
else
  # ActiveRecord::InternalMetadata and SchemaMigration do not inherit from
  # ActiveRecord::Base in Rails 7.1 so we do not need to exclude them.
  %w(
    Delayed::Job
    PaperTrail::Version
    ActiveStorage::Attachment
    ActiveStorage::Blob
  )
end.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exclude_classes!Object



40
41
42
43
44
45
46
47
48
# File 'lib/journaled/audit_log.rb', line 40

def exclude_classes!
  excluded_classes.each do |name|
    if Rails.autoloaders.zeitwerk_enabled?
      zeitwerk_exclude!(name)
    else
      classic_exclude!(name)
    end
  end
end

.with_snapshotsObject



50
51
52
53
54
55
56
# File 'lib/journaled/audit_log.rb', line 50

def with_snapshots
  snapshots_enabled_was = snapshots_enabled
  self.snapshots_enabled = true
  yield
ensure
  self.snapshots_enabled = snapshots_enabled_was
end

.without_audit_loggingObject



58
59
60
61
62
63
64
# File 'lib/journaled/audit_log.rb', line 58

def without_audit_logging
  disabled_was = _disabled
  self._disabled = true
  yield
ensure
  self._disabled = disabled_was
end

Instance Method Details

#_audit_log_changesObject



216
217
218
# File 'lib/journaled/audit_log.rb', line 216

def _audit_log_changes
  previous_changes.except(*audit_log_config.ignored_columns)
end

#_emit_audit_log!(database_operation) ⇒ Object



207
208
209
210
211
212
213
214
# File 'lib/journaled/audit_log.rb', line 207

def _emit_audit_log!(database_operation)
  if audit_log_config.enabled?
    event = Journaled::AuditLog::Event.new(self, database_operation, _audit_log_changes, audit_log_config.enqueue_opts)
    ActiveSupport::Notifications.instrument('journaled.audit_log.journal', event: event) do
      event.journal!
    end
  end
end