Class: ActiveModel::Validations::PostcodeValidator
- Inherits:
-
EachValidator
- Object
- EachValidator
- ActiveModel::Validations::PostcodeValidator
- Defined in:
- lib/active_model/validations/postcode_validator.rb
Overview
:nodoc:
Instance Method Summary collapse
Instance Method Details
#check_validity! ⇒ Object
16 17 18 |
# File 'lib/active_model/validations/postcode_validator.rb', line 16 def check_validity! raise ArgumentError, ':country must be supplied' unless .include?(:country) end |
#validate_each(record, attribute, value) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/active_model/validations/postcode_validator.rb', line 8 def validate_each(record, attribute, value) country = option_call(record, :country) record.errors.add(attribute, :invalid_postcode) unless validator.valid?(value, country: country) rescue ::PostcodeValidator::Error # rubocop:disable Lint/HandleExceptions # When :country is not a valid country, just skip postcode validation # :country validation is developer's responsability end |