]> git.openstreetmap.org Git - rails.git/blob - app/helpers/acls_helper.rb
Merge pull request #7373 from kmpoppe/note-moderation-zone-message
[rails.git] / app / helpers / acls_helper.rb
1 # frozen_string_literal: true
2
3 module AclsHelper
4   # Format an IPAddr the way PostgreSQL's inet type does: host addresses
5   # are shown bare, while networks carry their prefix length.
6   def acl_address(address)
7     return nil if address.nil?
8
9     host_prefix = address.ipv4? ? 32 : 128
10
11     if address.prefix == host_prefix
12       address.to_s
13     else
14       "#{address}/#{address.prefix}"
15     end
16   end
17 end