Class: ActiveModel::Validations::TypeValidator
- Inherits:
-
EachValidator
- Object
- EachValidator
- ActiveModel::Validations::TypeValidator
- Defined in:
- lib/active_model/validations/type_validator.rb
Overview
Adds type validation to ActiveModel::Model.
Usage:
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/active_model/validations/type_validator.rb', line 15 def validate_each(record, attribute, value) classes = Array([:with] || [:in]) unless classes.any? { |klass| value.is_a? klass } allowed_classes = classes.to_sentence two_words_connector: " or ", last_word_connector: ", or " record.errors.add(attribute, ([:message] || "must be a #{allowed_classes}")) end end |