Class: ActiveModel::Validations::PostalCodeValidator

Inherits:
EachValidator
  • Object
show all
Defined in:
lib/postjoy/validator.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ PostalCodeValidator

Returns a new instance of PostalCodeValidator.



5
6
7
8
# File 'lib/postjoy/validator.rb', line 5

def initialize(options)
  options.reverse_merge!(message: "is invalid")
  super(options)
end

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



10
11
12
13
14
# File 'lib/postjoy/validator.rb', line 10

def validate_each(record, attribute, value)
  if !Postjoy.find(value)
    record.errors.add(attribute, options.fetch(:message), value: value)
  end
end