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.24.5 app/validators/ip_format_validator.rb
metasploit_data_models-0.24.1.pre.rspec.pre.3.pre.1 app/validators/ip_format_validator.rb
metasploit_data_models-0.24.1 app/validators/ip_format_validator.rb
metasploit_data_models-0.24.0 app/validators/ip_format_validator.rb
metasploit_data_models-0.23.3.pre.autoload app/validators/ip_format_validator.rb
metasploit_data_models-0.23.2 app/validators/ip_format_validator.rb
metasploit_data_models-0.23.2-java app/validators/ip_format_validator.rb
metasploit_data_models-0.23.1 app/validators/ip_format_validator.rb
metasploit_data_models-0.23.1-java app/validators/ip_format_validator.rb
metasploit_data_models-0.23.0 app/validators/ip_format_validator.rb
metasploit_data_models-0.23.0-java app/validators/ip_format_validator.rb
metasploit_data_models-0.22.8 app/validators/ip_format_validator.rb
metasploit_data_models-0.22.8-java app/validators/ip_format_validator.rb
metasploit_data_models-0.22.7 app/validators/ip_format_validator.rb
metasploit_data_models-0.22.7-java app/validators/ip_format_validator.rb
metasploit_data_models-0.22.6 app/validators/ip_format_validator.rb
metasploit_data_models-0.22.6-java app/validators/ip_format_validator.rb
metasploit_data_models-0.22.5 app/validators/ip_format_validator.rb
metasploit_data_models-0.22.5-java app/validators/ip_format_validator.rb
metasploit_data_models-0.22.4 app/validators/ip_format_validator.rb