Class: Ci::Group

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize, StaticModel
Defined in:
app/models/ci/group.rb

Overview

This domain model is a representation of a group of jobs that are related to each other, like `rspec 0 1`, `rspec 0 2`.

It is not persisted in the database.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods included from StaticModel

#==, #[], #destroyed?, #new_record?, #persisted?, #to_param

Constructor Details

#initialize(project, stage, name:, jobs:) ⇒ Group

Returns a new instance of Group.


18
19
20
21
22
23
# File 'app/models/ci/group.rb', line 18

def initialize(project, stage, name:, jobs:)
  @project = project
  @stage = stage
  @name = name
  @jobs = jobs
end

Instance Attribute Details

#jobsObject (readonly)

Returns the value of attribute jobs


14
15
16
# File 'app/models/ci/group.rb', line 14

def jobs
  @jobs
end

#nameObject (readonly)

Returns the value of attribute name


14
15
16
# File 'app/models/ci/group.rb', line 14

def name
  @name
end

#projectObject (readonly)

Returns the value of attribute project


14
15
16
# File 'app/models/ci/group.rb', line 14

def project
  @project
end

#stageObject (readonly)

Returns the value of attribute stage


14
15
16
# File 'app/models/ci/group.rb', line 14

def stage
  @stage
end

Class Method Details

.fabricate(project, stage) ⇒ Object


42
43
44
45
46
47
48
# File 'app/models/ci/group.rb', line 42

def self.fabricate(project, stage)
  stage.latest_statuses
    .sort_by(&:sortable_name).group_by(&:group_name)
    .map do |group_name, grouped_statuses|
      self.new(project, stage, name: group_name, jobs: grouped_statuses)
    end
end

Instance Method Details

#detailed_status(current_user) ⇒ Object


33
34
35
36
37
38
39
40
# File 'app/models/ci/group.rb', line 33

def detailed_status(current_user)
  if jobs.one?
    jobs.first.detailed_status(current_user)
  else
    Gitlab::Ci::Status::Group::Factory
      .new(self, current_user).fabricate!
  end
end

#statusObject


25
26
27
28
29
30
31
# File 'app/models/ci/group.rb', line 25

def status
  strong_memoize(:status) do
    Gitlab::Ci::Status::Composite
      .new(@jobs)
      .status
  end
end