Class: ATDIS::Validators::ValidValidator

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

Overview

This attribute itself needs to be valid

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



90
91
92
93
94
95
96
97
98
# File 'lib/atdis/validators.rb', line 90

def validate_each(record, attribute, value)
  return unless (value.respond_to?(:valid?) && !value.valid?) ||
                (value && !value.respond_to?(:valid?) && !value.all?(&:valid?))

  record.errors.add(
    attribute,
    ErrorMessage["is not valid (see further errors for details)", nil]
  )
end