Welcome to mirror list, hosted at ThFree Co, Russian Federation.

base.rb « query_analyzers « database « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5f321ece962a11acd54607c5b8746f418d3aa606 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# frozen_string_literal: true

module Gitlab
  module Database
    module QueryAnalyzers
      class Base
        # `Exception` to ensure that is not easily rescued when running in test env
        QueryAnalyzerError = Class.new(Exception) # rubocop:disable Lint/InheritException

        def self.suppressed?
          Thread.current[self.suppress_key]
        end

        def self.requires_tracking?(parsed)
          false
        end

        def self.suppress=(value)
          Thread.current[self.suppress_key] = value
        end

        def self.with_suppressed(value = true, &blk)
          previous = self.suppressed?
          self.suppress = value
          yield
        ensure
          self.suppress = previous
        end

        def self.begin!
          Thread.current[self.context_key] = {}
        end

        def self.end!
          Thread.current[self.context_key] = nil
        end

        def self.context
          Thread.current[self.context_key]
        end

        def self.enabled?
          raise NotImplementedError
        end

        def self.analyze(parsed)
          raise NotImplementedError
        end

        def self.context_key
          @context_key ||= "analyzer_#{self.analyzer_key}_context".to_sym
        end

        def self.suppress_key
          @suppress_key ||= "analyzer_#{self.analyzer_key}_suppressed".to_sym
        end

        def self.analyzer_key
          @analyzer_key ||= self.name.demodulize.underscore.to_sym
        end
      end
    end
  end
end