Class: Eaternet::ValidatedObject::TypeValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- Eaternet::ValidatedObject::TypeValidator
- Defined in:
- lib/eaternet/validated_object.rb
Overview
A custom validator which ensures an object is a certain class. It's here as a nested class in Eaternet::ValidatedObject for easy access by subclasses.
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ nil
72 73 74 75 76 77 78 79 |
# File 'lib/eaternet/validated_object.rb', line 72 def validate_each(record, attribute, value) expected = [:with] actual = value.class return if actual == expected msg = [:message] || "is class #{actual}, not #{expected}" record.errors.add attribute, msg end |