class Antivirus::Validator::ProfanityFilterValidator

Public Instance Methods

validate_each(record, attribute, value) click to toggle source
# File lib/antivirus/validator.rb, line 4
def validate_each(record, attribute, value)
  record.errors[attribute] << message if value && profane?(value)
end

Private Instance Methods

message() click to toggle source
# File lib/antivirus/validator.rb, line 18
def message
  t('antivirus.message', 'includes profane words.')
end
profane?(value) click to toggle source
# File lib/antivirus/validator.rb, line 10
def profane?(value)
  !!(value.downcase =~ Regexp.union(profane_words.map(&:downcase)))
end
profane_words() click to toggle source
# File lib/antivirus/validator.rb, line 14
def profane_words
  t('antivirus.profane_words', [])
end
t(key, default) click to toggle source
# File lib/antivirus/validator.rb, line 22
def t(key, default)
  value = I18n.t(key, default: '')
  value.presence || default
end