Skip to content

Commit

Permalink
Merge pull request #69 from Cofense/do-not-cast-IPAddr-unnecessarily
Browse files Browse the repository at this point in the history
Do not cast to IPAddr unnecessarily
  • Loading branch information
oschwald authored Sep 25, 2023
2 parents 38e3b3e + 16a5950 commit 524f4fa
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/maxmind/db.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ def initialize(database, options = {})
#
# If no record is found for the IP address, +get+ returns +nil+.
#
# @param ip_address [String] a string in the standard notation. It may be
# IPv4 or IPv6.
# @param ip_address [String, IPAddr] IPv4 or IPv6 address.
#
# @raise [ArgumentError] if you attempt to look up an IPv6 address in an
# IPv4-only database.
Expand All @@ -153,8 +152,7 @@ def get(ip_address)
# If no record is found for the IP address, the record will be +nil+ and
# the prefix length will be the value for the missing network.
#
# @param ip_address [String] a string in the standard notation. It may be
# IPv4 or IPv6.
# @param ip_address [String, IPAddr] IPv4 or IPv6 address.
#
# @raise [ArgumentError] if you attempt to look up an IPv6 address in an
# IPv4-only database.
Expand All @@ -163,7 +161,8 @@ def get(ip_address)
#
# @return [Array<(Object, Integer)>]
def get_with_prefix_length(ip_address)
ip = IPAddr.new(ip_address)
ip = ip_address.is_a?(IPAddr) ? ip_address : IPAddr.new(ip_address)

# We could check the IP has the correct prefix (32 or 128) but I do not
# for performance reasons.

Expand Down

0 comments on commit 524f4fa

Please sign in to comment.