Class: AuditLoggable::Extension::Callbacks

Inherits:
Object
  • Object
show all
Defined in:
lib/audit_loggable/extension.rb

Instance Method Summary collapse

Constructor Details

#initialize(except: [], redacted: []) ⇒ Callbacks

Returns a new instance of Callbacks.



19
20
21
22
# File 'lib/audit_loggable/extension.rb', line 19

def initialize(except: [], redacted: [])
  @ignored_attributes = ::Array.wrap(except).map(&:to_s)
  @redacted_attributes = ::Array.wrap(redacted).map(&:to_s)
end

Instance Method Details

#after_commit(model) ⇒ Object



52
53
54
55
56
# File 'lib/audit_loggable/extension.rb', line 52

def after_commit(model)
  return if model.audit_loggable_audit_record_set.blank?

  persist_audit_record_set(model)
end

#after_create(model) ⇒ Object



24
25
26
27
28
29
# File 'lib/audit_loggable/extension.rb', line 24

def after_create(model)
  changeset = build_changeset_for_create(model)

  audit_record = build_audit_record(model, :create, changeset)
  add_audit_record(model, audit_record)
end

#after_destroy(model) ⇒ Object



39
40
41
42
43
44
# File 'lib/audit_loggable/extension.rb', line 39

def after_destroy(model)
  changeset = build_changeset_for_destroy(model)

  audit_record = build_audit_record(model, :destroy, changeset)
  add_audit_record(model, audit_record)
end

#after_rollback(model) ⇒ Object



46
47
48
49
50
# File 'lib/audit_loggable/extension.rb', line 46

def after_rollback(model)
  return if model.audit_loggable_audit_record_set.blank?

  clear_audit_record_set(model)
end

#after_update(model) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/audit_loggable/extension.rb', line 31

def after_update(model)
  changeset = build_changeset_for_update(model)
  return if changeset.blank?

  audit_record = build_audit_record(model, :update, changeset)
  add_audit_record(model, audit_record)
end