Commit e0ce97fb authored by Grzegorz Bizon's avatar Grzegorz Bizon

Refactor ci status factories to DRY code a little

parent feaf0180
...@@ -3,14 +3,13 @@ module Gitlab ...@@ -3,14 +3,13 @@ module Gitlab
module Status module Status
module Build module Build
class Factory < Status::Factory class Factory < Status::Factory
private def self.extended_statuses
[Status::Build::Stop, Status::Build::Play,
def extended_statuses Status::Build::Cancelable, Status::Build::Retryable]
[Stop, Play, Cancelable, Retryable]
end end
def core_status def self.common_helpers
super.extend(Status::Build::Common) Status::Build::Common
end end
end end
end end
......
...@@ -2,7 +2,7 @@ module Gitlab ...@@ -2,7 +2,7 @@ module Gitlab
module Ci module Ci
module Status module Status
module Extended module Extended
def matches?(_subject) def matches?(_subject, _user)
raise NotImplementedError raise NotImplementedError
end end
end end
......
...@@ -2,10 +2,9 @@ module Gitlab ...@@ -2,10 +2,9 @@ module Gitlab
module Ci module Ci
module Status module Status
class Factory class Factory
attr_reader :subject def initialize(subject, user = nil)
def initialize(subject)
@subject = subject @subject = subject
@user = user
end end
def fabricate! def fabricate!
...@@ -16,27 +15,32 @@ module Gitlab ...@@ -16,27 +15,32 @@ module Gitlab
end end
end end
def self.extended_statuses
[]
end
def self.common_helpers
Module.new
end
private private
def subject_status def simple_status
@subject_status ||= subject.status @simple_status ||= @subject.status || :created
end end
def core_status def core_status
Gitlab::Ci::Status Gitlab::Ci::Status
.const_get(subject_status.capitalize) .const_get(simple_status.capitalize)
.new(subject) .new(@subject)
.extend(self.class.common_helpers)
end end
def extended_status def extended_status
@extended ||= extended_statuses.find do |status| @extended ||= self.class.extended_statuses.find do |status|
status.matches?(subject) status.matches?(@subject, @user)
end end
end end
def extended_statuses
[]
end
end end
end end
end end
......
...@@ -3,14 +3,12 @@ module Gitlab ...@@ -3,14 +3,12 @@ module Gitlab
module Status module Status
module Pipeline module Pipeline
class Factory < Status::Factory class Factory < Status::Factory
private def self.extended_statuses
def extended_statuses
[Pipeline::SuccessWithWarnings] [Pipeline::SuccessWithWarnings]
end end
def core_status def self.common_helpers
super.extend(Status::Pipeline::Common) Status::Pipeline::Common
end end
end end
end end
......
...@@ -3,10 +3,8 @@ module Gitlab ...@@ -3,10 +3,8 @@ module Gitlab
module Status module Status
module Stage module Stage
class Factory < Status::Factory class Factory < Status::Factory
private def self.common_helpers
Status::Stage::Common
def core_status
super.extend(Status::Stage::Common)
end end
end 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