Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dynamic max_audits to be proc or symbol #718

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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