Skip to content

Commit

Permalink
Merge pull request collectiveidea#718 from downhome/dynamic-max-audits
Browse files Browse the repository at this point in the history
dynamic max_audits to be proc or symbol
  • Loading branch information
danielmorrison authored Jul 30, 2024
2 parents 5e504ec + 9a628a5 commit 0e019bb
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/audited/auditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,25 @@ def comment_required_state?
end

def combine_audits_if_needed
max_audits = audited_options[:max_audits]
max_audits = evaluate_max_audits

if max_audits && (extra_count = audits.count - max_audits) > 0
audits_to_combine = audits.limit(extra_count + 1)
combine_audits(audits_to_combine)
end
end

def evaluate_max_audits
max_audits = case (option = audited_options[:max_audits])
when Proc then option.call
when Symbol then send(option)
else
option
end

Integer(max_audits).abs if max_audits
end

def require_comment
if auditing_enabled && audit_comment.blank?
errors.add(:audit_comment, :blank)
Expand Down Expand Up @@ -502,8 +514,7 @@ def normalize_audited_options
audited_options[:on] = ([:create, :update, :touch, :destroy] - Audited.ignored_default_callbacks) if audited_options[:on].empty?
audited_options[:only] = Array.wrap(audited_options[:only]).map(&:to_s)
audited_options[:except] = Array.wrap(audited_options[:except]).map(&:to_s)
max_audits = audited_options[:max_audits] || Audited.max_audits
audited_options[:max_audits] = Integer(max_audits).abs if max_audits
audited_options[:max_audits] ||= Audited.max_audits
end

def calculate_non_audited_columns
Expand Down

0 comments on commit 0e019bb

Please sign in to comment.