Class: Ci::Group
- Inherits:
-
Object
- Object
- Ci::Group
- Includes:
- Gitlab::Utils::StrongMemoize, GlobalID::Identification, 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
-
#jobs ⇒ Object
readonly
Returns the value of attribute jobs.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#stage ⇒ Object
readonly
Returns the value of attribute stage.
Class Method Summary collapse
-
.fabricate(project, stage, statuses = nil) ⇒ Object
Construct a grouping of statuses for this stage.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #detailed_status(current_user) ⇒ Object
- #has_warnings? ⇒ Boolean
- #id ⇒ Object
-
#initialize(project, stage, name:, jobs:) ⇒ Group
constructor
A new instance of Group.
- #status ⇒ Object
- #status_struct ⇒ Object
- #success? ⇒ Boolean
Methods included from StaticModel
#[], #destroyed?, #new_record?, #persisted?, #to_param
Constructor Details
#initialize(project, stage, name:, jobs:) ⇒ Group
Returns a new instance of Group.
32 33 34 35 36 37 |
# File 'app/models/ci/group.rb', line 32 def initialize(project, stage, name:, jobs:) @project = project @stage = stage @name = name @jobs = jobs end |
Instance Attribute Details
#jobs ⇒ Object (readonly)
Returns the value of attribute jobs.
15 16 17 |
# File 'app/models/ci/group.rb', line 15 def jobs @jobs end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'app/models/ci/group.rb', line 15 def name @name end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
15 16 17 |
# File 'app/models/ci/group.rb', line 15 def project @project end |
#stage ⇒ Object (readonly)
Returns the value of attribute stage.
15 16 17 |
# File 'app/models/ci/group.rb', line 15 def stage @stage end |
Class Method Details
.fabricate(project, stage, statuses = nil) ⇒ Object
Construct a grouping of statuses for this stage. We allow the caller to pass in statuses for efficiency (avoiding N+1 queries).
22 23 24 25 26 27 28 29 30 |
# File 'app/models/ci/group.rb', line 22 def self.fabricate(project, stage, statuses = nil) statuses ||= stage.latest_statuses 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
#==(other) ⇒ Object
43 44 45 46 47 48 |
# File 'app/models/ci/group.rb', line 43 def ==(other) other.present? && other.is_a?(self.class) && project == other.project && stage == other.stage && name == other.name end |
#detailed_status(current_user) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'app/models/ci/group.rb', line 70 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 |
#has_warnings? ⇒ Boolean
60 61 62 |
# File 'app/models/ci/group.rb', line 60 def has_warnings? status_struct.warnings? end |
#id ⇒ Object
39 40 41 |
# File 'app/models/ci/group.rb', line 39 def id "#{stage.id}-#{name}" end |
#status ⇒ Object
50 51 52 53 54 |
# File 'app/models/ci/group.rb', line 50 def status strong_memoize(:status) do status_struct.status end end |
#status_struct ⇒ Object
64 65 66 67 68 |
# File 'app/models/ci/group.rb', line 64 def status_struct strong_memoize(:status_struct) do Gitlab::Ci::Status::Composite.new(@jobs) end end |
#success? ⇒ Boolean
56 57 58 |
# File 'app/models/ci/group.rb', line 56 def success? status.to_s == 'success' end |