Class: ActiveModel::Validations::LicensePlateValidator
- Inherits:
-
EachValidator
- Object
- EachValidator
- ActiveModel::Validations::LicensePlateValidator
- Defined in:
- lib/license_plate_validator/active_model.rb
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/license_plate_validator/active_model.rb', line 7 def validate_each(record, attribute, value) country = case([:country]) when Proc then [:country].call(record) when nil then nil else [:country].to_sym end license_plate = ::LicensePlateValidator.new(value.to_s, { country: country }) if !license_plate.valid? record.errors.add(attribute, :invalid_license_plate, message: [:message]) end end |