Class: IsraeliPostalCodeValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- IsraeliPostalCodeValidator
- Defined in:
- lib/israeli/active_model/israeli_postal_code_validator.rb
Overview
Validates that an attribute is a valid Israeli postal code (Mikud).
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/israeli/active_model/israeli_postal_code_validator.rb', line 17 def validate_each(record, attribute, value) return if value.blank? && [:allow_blank] return if value.nil? && [:allow_nil] return if Israeli::Validators::PostalCode.valid?(value) reason = Israeli::Validators::PostalCode.invalid_reason(value) record.errors.add( attribute, [:message] || :invalid, reason: reason ) end |