summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/reports/security/locations/base.rb
blob: 9ad1d81287f33b8439de6d2e5d721489b53f365b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# frozen_string_literal: true

module Gitlab
  module Ci
    module Reports
      module Security
        module Locations
          class Base
            include ::Gitlab::Utils::StrongMemoize

            def ==(other)
              other.fingerprint == fingerprint
            end

            def fingerprint
              strong_memoize(:fingerprint) do
                Digest::SHA1.hexdigest(fingerprint_data)
              end
            end

            def as_json(options = nil)
              fingerprint # side-effect call to initialize the ivar for serialization

              super
            end

            def fingerprint_path
              fingerprint_data
            end

            private

            def fingerprint_data
              raise NotImplementedError
            end
          end
        end
      end
    end
  end
end