Class: Cel::IP

Inherits:
Literal
  • Object
show all
Defined in:
lib/cel/extensions/network.rb

Overview

Constant Summary collapse

IPV4_LL_UC_CIDR =
IPAddr.new("169.254.0.0/16")
IPV4_LL_MC_CIDR =
IPAddr.new("224.0.0.0/24")
IPV6_LL_UC_CIDR =
IPAddr.new("fe80::/10")
IPV6_LL_MC_CIDR =
IPAddr.new("ff00::/8")

Instance Attribute Summary

Attributes inherited from Literal

#type, #value

Instance Method Summary collapse

Methods inherited from Literal

to_cel_type

Methods included from CelMethods

included

Constructor Details

#initialize(val) ⇒ IP

Returns a new instance of IP.



114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/cel/extensions/network.rb', line 114

def initialize(val)
  value = IPAddr.new(val)

  if value.ipv6?
    raise EvaluateError, "IP Address with zone value is not allowed" if value.zone_id

    if Resolv::IPv4::Regex.match?(val.split(":").last)
      raise EvaluateError, "IPv4-mapped IPv6 address is not allowed"
    end
  end

  super(:ip, value)
end