1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
module KDL
module Types
class IP < Value
def self.call(value, type = ip_type)
return nil unless value.is_a? ::KDL::Value::String
ip = ::IPAddr.new(value.value)
raise ArgumentError, "invalid #{ip_type} address" unless valid_ip?(ip)
new(ip, type: type)
end
def self.valid_ip?(ip)
ip.__send__(:"#{ip_type}?")
end
end
class IPV4 < IP
def self.ip_type
'ipv4'
end
end
MAPPING['ipv4'] = IPV4
class IPV6 < IP
def self.ip_type
'ipv6'
end
end
MAPPING['ipv6'] = IPV6
end
end
|