class RuboCop::Cop::Style::IpAddresses

ip_address = ENV[‘DEPLOYMENT_IP_ADDRESS’]
# good
ip_address = ‘127.59.241.29’
# bad
@example
other configuration.
a deployment if forgotten. Prefer setting IP addresses in ENV or
is deployed to a different server or environment, which may break
brittle. IP addresses are likely to need to be changed when code
Checks for hardcoded IP addresses, which can make code

def allowed_addresses

def allowed_addresses
  allowed_addresses = cop_config['AllowedAddresses']
  Array(allowed_addresses).map(&:downcase)
end

def correct_style_detected; end

called from StringHelp.
Dummy implementation of method in ConfigurableEnforcedStyle that is
def correct_style_detected; end

def offense?(node)

def offense?(node)
  contents = node.source[1...-1]
  return false if contents.empty?
  return false if allowed_addresses.include?(contents.downcase)
  # To try to avoid doing two regex checks on every string,
  # shortcut out if the string does not look like an IP address
  return false unless potential_ip?(contents)
  ::Resolv::IPv4::Regex.match?(contents) || ::Resolv::IPv6::Regex.match?(contents)
end

def opposite_style_detected; end

called from StringHelp.
Dummy implementation of method in ConfigurableEnforcedStyle that is
def opposite_style_detected; end

def potential_ip?(str)

def potential_ip?(str)
  # If the string is too long, it can't be an IP
  return false if too_long?(str)
  # If the string doesn't start with a colon or hexadecimal char,
  # we know it's not an IP address
  starts_with_hex_or_colon?(str)
end

def starts_with_hex_or_colon?(str)

def starts_with_hex_or_colon?(str)
  first_char = str[0].ord
  (48..58).cover?(first_char) || (65..70).cover?(first_char) || (97..102).cover?(first_char)
end

def too_long?(str)

def too_long?(str)
  str.size > IPV6_MAX_SIZE
end