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



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/atdis/validators.rb', line 62

def validate_each(record, attribute, value)
  if value && !value.is_a?(Array)
    message = "should be an array"
    message = ErrorMessage[message, options[:spec_section]] if options[:spec_section]
    record.errors.add(attribute, message)
  end
  return unless value&.is_a?(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