validator.rb 521 B

12345678910111213141516
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Setting::Validator < ActiveModel::Validator
  3. def validate(record)
  4. return if record.preferences.blank? || record.preferences[:validations].blank?
  5. failed_validation = record.preferences[:validations]
  6. .lazy
  7. .map { |klass| klass.constantize.new(record).run }
  8. .find { |elem| !elem[:success] }
  9. return if !failed_validation
  10. record.errors.add(:base, :invalid, message: failed_validation[:message])
  11. end
  12. end