Class: ATDIS::Validators::FilledArrayValidator

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

Overview

Can’t be an empty array

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/atdis/validators.rb', line 59

def validate_each(record, attribute, value)
  if value && !value.kind_of?(Array)
    message = "should be an array"
    message = ErrorMessage[message, options[:spec_section]] if options[:spec_section]
    record.errors.add(attribute, message)
  end
  if value && value.kind_of?(Array) && value.empty?
    message = "should not be an empty array"
    message = ErrorMessage[message, options[:spec_section]] if options[:spec_section]
    record.errors.add(attribute, message)
  end
end