1 class NormalizedUniquenessValidator < ActiveModel::EachValidator
 
   2   def validate_each(record, attribute, value)
 
   3     relation = if options.fetch(:case_sensitive, true)
 
   4                  record.class.where("NORMALIZE(#{attribute}, NFKC) = NORMALIZE(?, NFKC)", value)
 
   6                  record.class.where("LOWER(NORMALIZE(#{attribute}, NFKC)) = LOWER(NORMALIZE(?, NFKC))", value)
 
   9     relation = relation.where.not(record.class.primary_key => [record.id_in_database]) if record.persisted?
 
  12       error_options = options.except(:case_sensitive)
 
  13       error_options[:value] = value
 
  15       record.errors.add(attribute, :taken, **error_options)