Class: Staypuft::Deployment::NeutronService::Cisconexus::IpValueValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/models/staypuft/deployment/neutron_service/cisconexus.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/staypuft/deployment/neutron_service/cisconexus.rb', line 32

def validate_each(record, attribute, value)
  return if value.empty?

  ip_addr = IPAddr.new(value)
  ip_range = ip_addr.to_range
  if ip_range.begin == ip_range.end
    true
  else
    record.errors.add attribute, "Specify single IP address, not range"
    false
  end
end