module AuditWeasel::Base

Base functionality to check if a model requires auditing, get the fields that need to be updated and update the auditing fields with the user making the changes

Private Instance Methods

audit_fields() click to toggle source
# File lib/audit_weasel/base.rb, line 33
def audit_fields
  create_audit_fields + update_audit_fields
end
audit_user() click to toggle source
# File lib/audit_weasel/base.rb, line 14
def audit_user
  update_fields if current_user
end
create_audit_fields() click to toggle source
# File lib/audit_weasel/base.rb, line 41
def create_audit_fields
  [:created_by_user_id]
end
current_user() click to toggle source
# File lib/audit_weasel/base.rb, line 45
def current_user
  RequestRegistry.current_user
end
fields_to_update() click to toggle source
# File lib/audit_weasel/base.rb, line 25
def fields_to_update
  if self.new_record?
    audit_fields
  else
    update_audit_fields
  end
end
update_audit_fields() click to toggle source
# File lib/audit_weasel/base.rb, line 37
def update_audit_fields
  [:updated_by_user_id]
end
update_fields() click to toggle source
# File lib/audit_weasel/base.rb, line 18
def update_fields
  fields_to_update.each do |column|
    column = column.to_s
    self[column] = current_user.id if has_attribute?(column)
  end
end