mirror of
https://github.com/mastodon/mastodon.git
synced 2025-01-10 17:10:28 +00:00
16 lines
424 B
Ruby
16 lines
424 B
Ruby
# frozen_string_literal: true
|
|
|
|
class EmptyProfileFieldNamesValidator < ActiveModel::Validator
|
|
def validate(account)
|
|
return if account.fields.empty?
|
|
|
|
account.errors.add(:fields, :fields_with_values_missing_labels) if fields_with_values_missing_names?(account)
|
|
end
|
|
|
|
private
|
|
|
|
def fields_with_values_missing_names?(account)
|
|
account.fields.any? { |field| field.name.blank? && field.value.present? }
|
|
end
|
|
end
|