Sha256: df177c912595ca850bfb93aa6d563306f6b5f1ea6e9975fed2f277684c091f1e

Contents?: true

Size: 423 Bytes

Versions: 107

Compression:

Stored size: 423 Bytes

Contents

require "ipaddr"

class IpFormatValidator < ActiveModel::EachValidator
  def validate_each(object, attribute, value)
    error_message_block = lambda{ object.errors[attribute] << " must be a valid IPv4 or IPv6 address" }
    begin
      potential_ip = IPAddr.new(value)
      error_message_block.call unless potential_ip.ipv4? || potential_ip.ipv6?
    rescue ArgumentError
      error_message_block.call
    end
  end
end

Version data entries

107 entries across 107 versions & 1 rubygems

Version Path
metasploit_data_models-0.19.8 app/validators/ip_format_validator.rb
metasploit_data_models-0.19.8-java app/validators/ip_format_validator.rb
metasploit_data_models-0.19.7 app/validators/ip_format_validator.rb
metasploit_data_models-0.19.7-java app/validators/ip_format_validator.rb
metasploit_data_models-0.19.4 app/validators/ip_format_validator.rb
metasploit_data_models-0.19.4-java app/validators/ip_format_validator.rb
metasploit_data_models-0.19.3-java app/validators/ip_format_validator.rb
metasploit_data_models-0.19.3 app/validators/ip_format_validator.rb
metasploit_data_models-0.19.0 app/validators/ip_format_validator.rb
metasploit_data_models-0.19.0-java app/validators/ip_format_validator.rb
metasploit_data_models-0.18.1-java app/validators/ip_format_validator.rb
metasploit_data_models-0.18.1 app/validators/ip_format_validator.rb
metasploit_data_models-0.18.0 app/validators/ip_format_validator.rb
metasploit_data_models-0.18.0-java app/validators/ip_format_validator.rb
metasploit_data_models-0.18.0.pre.compatibility app/validators/ip_format_validator.rb
metasploit_data_models-0.17.3-java app/validators/ip_format_validator.rb
metasploit_data_models-0.17.3 app/validators/ip_format_validator.rb
metasploit_data_models-0.17.3.pre.metasploit.pre.concern-java app/validators/ip_format_validator.rb
metasploit_data_models-0.17.3.pre.metasploit.pre.concern app/validators/ip_format_validator.rb
metasploit_data_models-0.17.2-java app/validators/ip_format_validator.rb