c9b1095d1e
In Ruby 2.7, Enumerable#filter_map has been added. This cop identifies places where map { … }.compact can be replaced by filter_map. See: https://docs.rubocop.org/rubocop-performance/cops_performance.html#performancemapcompact
30 lines
526 B
Ruby
30 lines
526 B
Ruby
class IPService
|
|
class << self
|
|
def ip_trusted?(ip)
|
|
ip_address = parse_address(ip)
|
|
|
|
trusted_networks.any? { |network| network.include?(ip_address) }
|
|
end
|
|
|
|
private
|
|
|
|
def trusted_networks
|
|
if ENV['TRUSTED_NETWORKS'].present?
|
|
ENV['TRUSTED_NETWORKS']
|
|
.split
|
|
.filter_map { |string| parse_address(string) }
|
|
|
|
else
|
|
[]
|
|
end
|
|
end
|
|
|
|
def parse_address(address)
|
|
begin
|
|
IPAddr.new(address)
|
|
rescue
|
|
nil
|
|
end
|
|
end
|
|
end
|
|
end
|