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

resource_group.rb « processable « seed « pipeline « ci « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f8ea6d4184cd9969dac357a4ba637a43daca734e (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
# frozen_string_literal: true

module Gitlab
  module Ci
    module Pipeline
      module Seed
        module Processable
          class ResourceGroup < Seed::Base
            include Gitlab::Utils::StrongMemoize

            attr_reader :processable, :resource_group_key

            def initialize(processable, resource_group_key)
              @processable = processable
              @resource_group_key = resource_group_key
            end

            def to_resource
              return unless resource_group_key.present?

              resource_group = processable.project.resource_groups
                .safe_find_or_create_by(key: expanded_resource_group_key)

              resource_group if resource_group.persisted?
            end

            private

            def expanded_resource_group_key
              strong_memoize(:expanded_resource_group_key) do
                ExpandVariables.expand(resource_group_key, -> { processable.simple_variables })
              end
            end
          end
        end
      end
    end
  end
end