Class: HoyganValidator

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

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



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

def validate_each(record, attribute, value)
  if options[:with] == false
    Hoygancop.report(value).each do |error|
      record.errors.add attribute, "hoygan.#{error}".to_sym
    end
  else
    record.errors.add attribute, :not_hoygan unless Hoygancop.hoygan?(value)
  end
end