Class: Cel::CIDR

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

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) ⇒ CIDR

Returns a new instance of CIDR.



178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/cel/extensions/network.rb', line 178

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

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

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

  super(:cidr, value)
end

Instance Method Details

#to_strObject



213
214
215
# File 'lib/cel/extensions/network.rb', line 213

def to_str
  @value.cidr
end