Class: ObsceneContentValidator

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

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/obscene_gpt/active_model.rb', line 9

def validate(record)
  to_validate = compute_attributes_to_validate(record)
  return if to_validate.empty?

  results = ObsceneGpt.detect_many(to_validate.values)
  format_errors(record, to_validate, results)
rescue ObsceneGpt::Error => e
  raise e unless options[:ignore_errors]
end