ip addresses: move more logic to Danbooru::IpAddress.

* Move `is_local?` from IpLookup to Danbooru::IpAddress.
* Refactor more things to use Danbooru::IpAddress instead of using
  IPAddress directly.
This commit is contained in:
evazion
2021-03-01 16:35:55 -06:00
parent 35a0c6b11f
commit 92b8f24724
8 changed files with 47 additions and 37 deletions

View File

@@ -79,10 +79,10 @@ module Searchable
def where_inet_matches(attr, value)
if value.match?(/[, ]/)
ips = value.split(/[, ]+/).map { |ip| IPAddress.parse(ip).to_string }
ips = value.split(/[, ]+/).map { |ip| Danbooru::IpAddress.new(ip).to_string }
where("#{qualified_column_for(attr)} = ANY(ARRAY[?]::inet[])", ips)
else
ip = IPAddress.parse(value)
ip = Danbooru::IpAddress.new(value)
where("#{qualified_column_for(attr)} <<= ?", ip.to_string)
end
end