Class: CensoredWordsValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- CensoredWordsValidator
- Defined in:
- lib/validators/censored_words_validator.rb
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/validators/censored_words_validator.rb', line 4 def validate_each(record, attribute, value) words_regexps = WordWatcher.compiled_regexps_for_action(:censor) if WordWatcher.words_for_action_exist?(:censor).present? && words_regexps.present? censored_words = censor_words(value, words_regexps) return if censored_words.blank? record.errors.add( attribute, :contains_censored_words, censored_words: join_censored_words(censored_words), ) end end |