Class: ActiveModel::Validations::ObscenityValidator

Inherits:
EachValidator
  • Object
show all
Defined in:
lib/obscenity/active_model.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/obscenity/active_model.rb', line 6

def validate_each(record, attribute, value)
  if options.present? && options.has_key?(:sanitize)
    object = record.respond_to?(:[]) ? record[attribute] : record.send(attribute)
    object = Obscenity.replacement(options[:replacement]).sanitize(object)
  else
    record.errors.add(attribute, options[:message] || 'cannot be profane') if Obscenity.profane?(value)
  end
end