backend.rb 583 B

1234567891011121314151617181920
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Validations::ObjectManager::AttributeValidator::Backend
  3. def self.validate(...)
  4. new(...).validate
  5. end
  6. attr_reader :record, :attribute, :value, :previous_value
  7. def initialize(record:, attribute:)
  8. @record = record
  9. @attribute = attribute
  10. @value = record[attribute.name]
  11. @previous_value = record.attribute_in_database(attribute.name)
  12. end
  13. def invalid_because_attribute(message, **)
  14. record.errors.add attribute.name.to_sym, message, **
  15. end
  16. end