mirror of
https://git.bsd.gay/fef/nyastodon.git
synced 2024-12-27 23:33:42 +01:00
23 lines
449 B
Ruby
23 lines
449 B
Ruby
# frozen_string_literal: true
|
|
|
|
class LanguageValidator < ActiveModel::EachValidator
|
|
include LanguagesHelper
|
|
|
|
def validate_each(record, attribute, value)
|
|
@value = value
|
|
|
|
record.errors.add(attribute, :invalid) unless valid_locale_value?
|
|
end
|
|
|
|
private
|
|
|
|
def valid_locale_value?
|
|
if @value.nil?
|
|
true
|
|
elsif @value.is_a?(Array)
|
|
@value.all? { |x| valid_locale?(x) }
|
|
else
|
|
valid_locale?(@value)
|
|
end
|
|
end
|
|
end
|