Class: Trackdown::IpValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/trackdown/ip_validator.rb

Defined Under Namespace

Classes: InvalidIpError

Class Method Summary collapse

Class Method Details

.private_ip?(ip) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/trackdown/ip_validator.rb', line 19

def self.private_ip?(ip)
  addr = IPAddr.new(ip.to_s)
  addr.private? || addr.loopback?
end

.validate!(ip) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/trackdown/ip_validator.rb', line 9

def self.validate!(ip)
  return if ip.nil?

  begin
    IPAddr.new(ip.to_s)
  rescue IPAddr::InvalidAddressError
    raise InvalidIpError, "Invalid IP address format: #{ip}"
  end
end