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

batched_background_migrations_dictionary.rb « rubocop - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 70892d20796c6a529a7031a8055092da5b5b1335 (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
# frozen_string_literal: true

module RuboCop
  class BatchedBackgroundMigrationsDictionary
    DICTIONARY_BASE_DIR = 'db/docs/batched_background_migrations'

    attr_reader :queued_migration_version

    class << self
      def dictionary_data
        @dictionary_data ||= Dir.glob("*.yml", base: DICTIONARY_BASE_DIR).each_with_object({}) do |file_name, data|
          dictionary = YAML.load_file(File.join(DICTIONARY_BASE_DIR, file_name))

          next unless dictionary['queued_migration_version'].present?

          data[dictionary['queued_migration_version'].to_s] = {
            introduced_by_url: dictionary['introduced_by_url'],
            finalize_after: dictionary['finalize_after'],
            finalized_by: dictionary['finalized_by'].to_s,
            milestone: dictionary['milestone']
          }
        end
      end
    end

    def initialize(queued_migration_version)
      @queued_migration_version = queued_migration_version
    end

    def finalized_by
      dictionary_data&.dig(:finalized_by)
    end

    def finalize_after
      dictionary_data&.dig(:finalize_after)
    end

    def introduced_by_url
      dictionary_data&.dig(:introduced_by_url)
    end

    def milestone
      dictionary_data&.dig(:milestone)
    end

    private

    def dictionary_data
      @dictionary_data ||= self.class.dictionary_data[queued_migration_version.to_s]
    end
  end
end