Class: ActiveModel::Validations::IpFormatValidator

Inherits:
EachValidator
  • Object
show all
Defined in:
lib/active_model/validations/ip_format_validator.rb

Overview

The purpose of the IpFormatValidator class is to check the format of an IP address. The checks performed on the IP address are:

- Must either be IPv4 or IPv6 format
- Must be a public IP address

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object

Validates the IP address



27
28
29
# File 'lib/active_model/validations/ip_format_validator.rb', line 27

def validate_each(record, attribute, value)
    record.errors.add(attribute, 'is not a valid IP address') unless good_format(value)
end