Sha256: 23edaab59061f562310db7b256dad3c120da60e4a4d9ce4c1343c25639a757fb

Contents?: true

Size: 526 Bytes

Versions: 3

Compression:

Stored size: 526 Bytes

Contents

module IpAnonymizer
  class MaskIp
    def initialize(app)
      @app = app
    end

    def call(env)
      req = ActionDispatch::Request.new(env)
      # get header directly to preserve ActionDispatch::RemoteIp lazy loading
      req.remote_ip = GetIp.new(req.get_header("action_dispatch.remote_ip".freeze))
      @app.call(req.env)
    end

    class GetIp
      def initialize(remote_ip)
        @remote_ip = remote_ip
      end

      def to_s
        @ip ||= IpAnonymizer.mask_ip(@remote_ip)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ip_anonymizer-0.3.0 lib/ip_anonymizer/mask_ip.rb
ip_anonymizer-0.2.0 lib/ip_anonymizer/mask_ip.rb
ip_anonymizer-0.1.1 lib/ip_anonymizer/mask_ip.rb