class IpValidator

Public Instance Methods

validate_each(record, attribute, value) click to toggle source
# File lib/active_validation/validators/ip_validator.rb, line 5
def validate_each(record, attribute, value)
  return if valid?(value.to_s)

  record.errors[attribute] <<
    (options[:message] || I18n.t('active_validation.errors.messages.ip'))
end

Private Instance Methods

valid?(value) click to toggle source
# File lib/active_validation/validators/ip_validator.rb, line 24
def valid?(value)
  valid_length?(value) &&
    valid_format?(value)
end
valid_format?(value) click to toggle source

rubocop:disable Metrics/LineLength

# File lib/active_validation/validators/ip_validator.rb, line 15
def valid_format?(value)
  value =~ /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
end
valid_length?(value) click to toggle source

rubocop:enable Metrics/LineLength

# File lib/active_validation/validators/ip_validator.rb, line 20
def valid_length?(value)
  value.present?
end