Commit e0ce97fb authored by Grzegorz Bizon's avatar Grzegorz Bizon

Refactor ci status factories to DRY code a little

parent feaf0180
No related merge requests found
......@@ -3,14 +3,13 @@ module Gitlab
module Status
module Build
class Factory < Status::Factory
private
def extended_statuses
[Stop, Play, Cancelable, Retryable]
def self.extended_statuses
[Status::Build::Stop, Status::Build::Play,
Status::Build::Cancelable, Status::Build::Retryable]
end
def core_status
super.extend(Status::Build::Common)
def self.common_helpers
Status::Build::Common
end
end
end
......
......@@ -2,7 +2,7 @@ module Gitlab
module Ci
module Status
module Extended
def matches?(_subject)
def matches?(_subject, _user)
raise NotImplementedError
end
end
......
......@@ -2,10 +2,9 @@ module Gitlab
module Ci
module Status
class Factory
attr_reader :subject
def initialize(subject)
def initialize(subject, user = nil)
@subject = subject
@user = user
end
def fabricate!
......@@ -16,26 +15,31 @@ module Gitlab
end
end
def self.extended_statuses
[]
end
def self.common_helpers
Module.new
end
private
def subject_status
@subject_status ||= subject.status
def simple_status
@simple_status ||= @subject.status || :created
end
def core_status
Gitlab::Ci::Status
.const_get(subject_status.capitalize)
.new(subject)
.const_get(simple_status.capitalize)
.new(@subject)
.extend(self.class.common_helpers)
end
def extended_status
@extended ||= extended_statuses.find do |status|
status.matches?(subject)
end
@extended ||= self.class.extended_statuses.find do |status|
status.matches?(@subject, @user)
end
def extended_statuses
[]
end
end
end
......
......@@ -3,14 +3,12 @@ module Gitlab
module Status
module Pipeline
class Factory < Status::Factory
private
def extended_statuses
def self.extended_statuses
[Pipeline::SuccessWithWarnings]
end
def core_status
super.extend(Status::Pipeline::Common)
def self.common_helpers
Status::Pipeline::Common
end
end
end
......
......@@ -3,10 +3,8 @@ module Gitlab
module Status
module Stage
class Factory < Status::Factory
private
def core_status
super.extend(Status::Stage::Common)
def self.common_helpers
Status::Stage::Common
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment