0
0
Fork 0

Add ability to filter followed accounts' posts by language (#19095)

This commit is contained in:
Eugen Rochko 2022-09-20 23:51:21 +02:00 committed by GitHub
parent 882e54c786
commit 50948b46aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 298 additions and 39 deletions

View file

@ -0,0 +1,21 @@
# frozen_string_literal: true
class LanguageValidator < ActiveModel::EachValidator
include LanguagesHelper
def validate_each(record, attribute, value)
record.errors.add(attribute, :invalid) unless valid?(value)
end
private
def valid?(str)
if str.nil?
true
elsif str.is_a?(Array)
str.all? { |x| valid_locale?(x) }
else
valid_locale?(str)
end
end
end