Sha256: b71b33a771b45572e7d0437709cb6ac78683bd6be53ce4e2a4c0428cd4bfb45a

Contents?: true

Size: 643 Bytes

Versions: 19

Compression:

Stored size: 643 Bytes

Contents

# frozen_string_literal: true

require 'ipaddr'

module QuoVadis
  module IpMasking

    def self.included(base)
      base.extend ClassMethods
      base.before_validation :mask_ip, if: -> { QuoVadis.mask_ips }
    end

    def mask_ip
      self.ip = self.class.mask_ip ip
    end

    module ClassMethods
      # Based on Google Analytics masking
      # https://support.google.com/analytics/answer/2763052
      def mask_ip(ip)
        addr = IPAddr.new ip
        if addr.ipv4?
          addr.mask(24).to_s  # set last octet to 0
        else
          addr.mask(48).to_s  # set last 80 bits to 0
        end
      end
    end

  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
quo_vadis-2.2.4 lib/quo_vadis/ip_masking.rb
quo_vadis-2.2.2 lib/quo_vadis/ip_masking.rb
quo_vadis-2.2.1 lib/quo_vadis/ip_masking.rb
quo_vadis-2.2.0 lib/quo_vadis/ip_masking.rb
quo_vadis-2.1.11 lib/quo_vadis/ip_masking.rb
quo_vadis-2.1.10 lib/quo_vadis/ip_masking.rb
quo_vadis-2.1.9 lib/quo_vadis/ip_masking.rb
quo_vadis-2.1.8 lib/quo_vadis/ip_masking.rb
quo_vadis-2.1.7 lib/quo_vadis/ip_masking.rb
quo_vadis-2.1.6 lib/quo_vadis/ip_masking.rb
quo_vadis-2.1.5 lib/quo_vadis/ip_masking.rb
quo_vadis-2.1.4 lib/quo_vadis/ip_masking.rb
quo_vadis-2.1.3 lib/quo_vadis/ip_masking.rb
quo_vadis-2.1.2 lib/quo_vadis/ip_masking.rb
quo_vadis-2.1.1 lib/quo_vadis/ip_masking.rb
quo_vadis-2.1.0 lib/quo_vadis/ip_masking.rb
quo_vadis-2.0.2 lib/quo_vadis/ip_masking.rb
quo_vadis-2.0.1 lib/quo_vadis/ip_masking.rb
quo_vadis-2.0.0 lib/quo_vadis/ip_masking.rb