Class: IpFormatValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- IpFormatValidator
- Defined in:
- app/validators/ip_format_validator.rb
Instance Method Summary collapse
Instance Method Details
#validate_each(object, attribute, value) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'app/validators/ip_format_validator.rb', line 4 def validate_each(object, attribute, value) = lambda{ object.errors[attribute] << " must be a valid IPv4 or IPv6 address" } begin potential_ip = IPAddr.new(value) .call unless potential_ip.ipv4? || potential_ip.ipv6? rescue ArgumentError .call end end |