class AuditModel::Models::Base

Constants

BLACK_LIST

Public Class Methods

build(model, type) click to toggle source
# File lib/audit_model/models/base.rb, line 18
def build(model, type)
  return if type == :update && !any_change?(model)
  attrs = sanitize(model, type)
  attrs[:rev_type] = type
  new(attrs)
end

Private Class Methods

any_change?(model) click to toggle source
# File lib/audit_model/models/base.rb, line 36
def any_change?(model)
  model.changed? && model.changed_attributes.any? { |key,value| has_audit?(key) }
end
has_audit?(attribute) click to toggle source
# File lib/audit_model/models/base.rb, line 40
def has_audit?(attribute)
  attribute_names.include?(attribute)
end
sanitize(model, type) click to toggle source
# File lib/audit_model/models/base.rb, line 27
def sanitize(model, type)
  if type == :update
    attrs = model.attributes.merge(model.changed_attributes)
  elsif 
    attrs = model.attributes
  end
  attrs.except(*BLACK_LIST).select { |key,value| has_audit?(key) }
end

Public Instance Methods

who() click to toggle source
# File lib/audit_model/models/base.rb, line 13
def who
  revision.user
end