Class: Gitlab::Ci::Pipeline::Seed::Stage

Inherits:
Base
  • Object
show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/ci/pipeline/seed/stage.rb

Instance Method Summary collapse

Methods included from Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(pipeline, attributes, previous_stages) ⇒ Stage

Returns a new instance of Stage.


13
14
15
16
17
18
19
20
21
# File 'lib/gitlab/ci/pipeline/seed/stage.rb', line 13

def initialize(pipeline, attributes, previous_stages)
  @pipeline = pipeline
  @attributes = attributes
  @previous_stages = previous_stages

  @builds = attributes.fetch(:builds).map do |attributes|
    Seed::Build.new(@pipeline, attributes, previous_stages)
  end
end

Instance Method Details

#attributesObject


23
24
25
26
27
28
# File 'lib/gitlab/ci/pipeline/seed/stage.rb', line 23

def attributes
  { name: @attributes.fetch(:name),
    position: @attributes.fetch(:index),
    pipeline: @pipeline,
    project: @pipeline.project }
end

#errorsObject


36
37
38
39
40
# File 'lib/gitlab/ci/pipeline/seed/stage.rb', line 36

def errors
  strong_memoize(:errors) do
    seeds.flat_map(&:errors).compact
  end
end

#included?Boolean

Returns:

  • (Boolean)

48
49
50
# File 'lib/gitlab/ci/pipeline/seed/stage.rb', line 48

def included?
  seeds.any?
end

#seedsObject


30
31
32
33
34
# File 'lib/gitlab/ci/pipeline/seed/stage.rb', line 30

def seeds
  strong_memoize(:seeds) do
    @builds.select(&:included?)
  end
end

#seeds_namesObject


42
43
44
45
46
# File 'lib/gitlab/ci/pipeline/seed/stage.rb', line 42

def seeds_names
  strong_memoize(:seeds_names) do
    seeds.map(&:name).to_set
  end
end

#to_resourceObject


52
53
54
55
56
57
58
# File 'lib/gitlab/ci/pipeline/seed/stage.rb', line 52

def to_resource
  strong_memoize(:stage) do
    ::Ci::Stage.new(attributes).tap do |stage|
      stage.statuses = seeds.map(&:to_resource)
    end
  end
end