Module: Logga::ActiveRecord

Extended by:
ActiveSupport::Concern
Defined in:
lib/logga/active_record.rb

Instance Method Summary collapse

Instance Method Details

#log_field_changes(changes) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/logga/active_record.rb', line 43

def log_field_changes(changes)
  return if changes.blank?

  body = field_changes_to_message(changes)
  return if body.blank?

  create_log_entry(author_data.merge(body:))
end

#log_model_changesObject



68
69
70
71
72
73
# File 'lib/logga/active_record.rb', line 68

def log_model_changes
  return unless should_log?

  field_changes = previous_changes.reject { |k, _| reject_change?(k) }
  log_field_changes(field_changes)
end

#log_model_creationObject



52
53
54
55
56
57
58
# File 'lib/logga/active_record.rb', line 52

def log_model_creation
  return unless should_log?

  body_generator = ->(record) { default_creation_log_body(record) }
  body = logga_options[:fields].fetch(:created_at, body_generator).call(self)
  create_log_entry(author_data.merge(body:, created_at: creation_at))
end

#log_model_deletionObject



60
61
62
63
64
65
66
# File 'lib/logga/active_record.rb', line 60

def log_model_deletion
  return unless should_log?

  body_generator = ->(record) { default_deletion_log_body(record) }
  body = logga_options[:fields].fetch(:deleted_at, body_generator).call(self)
  create_log_entry(author_data.merge(body:))
end