Class: ActiveModel::Validations::TwinValidator
- Inherits:
-
EachValidator
- Object
- EachValidator
- ActiveModel::Validations::TwinValidator
- Defined in:
- lib/twin_validator.rb
Defined Under Namespace
Modules: HelperMethods
Instance Method Summary collapse
Instance Method Details
#check_validity! ⇒ Object
6 7 8 9 |
# File 'lib/twin_validator.rb', line 6 def check_validity! raise ArgumentError, "An Enumerable object is required and must be supplied as the " << ":twins option of the configuration hash" unless [:twins].respond_to?(:each) end |
#validate_each(record, attribute, value) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/twin_validator.rb', line 11 def validate_each(record, attribute, value) [:twins].each do |twin| value = record.send(:read_attribute_for_validation, twin) record.errors.add_on_blank(attribute, [:message]) if value end end |