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(context, attributes, previous_stages) ⇒ Stage

Returns a new instance of Stage.


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

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

  @builds = attributes.fetch(:builds).map do |attributes|
    Seed::Build.new(context, attributes, previous_stages + [self])
  end
end

Instance Method Details

#attributesObject


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

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

#errorsObject


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

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

#included?Boolean

Returns:

  • (Boolean)

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

def included?
  seeds.any?
end

#seedsObject


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

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

#seeds_namesObject


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

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

#to_resourceObject


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

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