Sha256: df177c912595ca850bfb93aa6d563306f6b5f1ea6e9975fed2f277684c091f1e
Contents?: true
Size: 423 Bytes
Versions: 107
Compression:
Stored size: 423 Bytes
Contents
require "ipaddr" class IpFormatValidator < ActiveModel::EachValidator def validate_each(object, attribute, value) error_message_block = lambda{ object.errors[attribute] << " must be a valid IPv4 or IPv6 address" } begin potential_ip = IPAddr.new(value) error_message_block.call unless potential_ip.ipv4? || potential_ip.ipv6? rescue ArgumentError error_message_block.call end end end
Version data entries
107 entries across 107 versions & 1 rubygems