]> git.openstreetmap.org Git - rails.git/blob - app/validators/inet_validator.rb
Test submitting no change to a user image
[rails.git] / app / validators / inet_validator.rb
1 # frozen_string_literal: true
2
3 # Validates that an inet/cidr column was given parseable input. ActiveRecord
4 # casts anything unparseable to nil, so the cast value alone can't tell a
5 # blank field from a typo; compare it against the raw input instead.
6 class InetValidator < ActiveModel::EachValidator
7   def validate_each(record, attribute, value)
8     raw = record.read_attribute_before_type_cast(attribute)
9     record.errors.add(attribute, options[:message] || :invalid) if raw.present? && value.nil?
10   end
11 end