2016-12-07 07:14:45 -05:00
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
module Status
|
|
|
|
class Factory
|
2016-12-08 08:28:49 -05:00
|
|
|
def initialize(subject, user)
|
2016-12-07 07:14:45 -05:00
|
|
|
@subject = subject
|
2016-12-08 07:51:06 -05:00
|
|
|
@user = user
|
2016-12-07 07:14:45 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def fabricate!
|
|
|
|
if extended_status
|
|
|
|
extended_status.new(core_status)
|
|
|
|
else
|
|
|
|
core_status
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-08 07:51:06 -05:00
|
|
|
def self.extended_statuses
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.common_helpers
|
|
|
|
Module.new
|
|
|
|
end
|
|
|
|
|
2016-12-07 07:14:45 -05:00
|
|
|
private
|
|
|
|
|
2016-12-08 07:51:06 -05:00
|
|
|
def simple_status
|
|
|
|
@simple_status ||= @subject.status || :created
|
2016-12-07 07:14:45 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def core_status
|
|
|
|
Gitlab::Ci::Status
|
2016-12-08 07:51:06 -05:00
|
|
|
.const_get(simple_status.capitalize)
|
2016-12-08 08:28:49 -05:00
|
|
|
.new(@subject, @user)
|
2016-12-08 07:51:06 -05:00
|
|
|
.extend(self.class.common_helpers)
|
2016-12-07 07:14:45 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def extended_status
|
2016-12-08 07:51:06 -05:00
|
|
|
@extended ||= self.class.extended_statuses.find do |status|
|
|
|
|
status.matches?(@subject, @user)
|
2016-12-07 07:14:45 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|