classKeyRestrictionValidator<ActiveModel::EachValidatorFORBIDDEN=-1defself.supported_sizes(type)Gitlab::SSHPublicKey.supported_sizes(type)enddefself.supported_key_restrictions(type)[0,*supported_sizes(type),FORBIDDEN]enddefvalidate_each(record,attribute,value)unlessvalid_restriction?(value)record.errors.add(attribute,"must be forbidden, allowed, or one of these sizes: #{supported_sizes_message}")endendprivatedefsupported_sizes_messagesizes=self.class.supported_sizes(options[:type])sizes.to_sentence(last_word_connector: ', or ',two_words_connector: ' or ')enddefvalid_restriction?(value)choices=self.class.supported_key_restrictions(options[:type])choices.include?(value)endend