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
|
2017-01-18 05:34:55 -05:00
|
|
|
@status = subject.status || HasStatus::DEFAULT_STATUS
|
2016-12-07 07:14:45 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def fabricate!
|
2017-01-12 06:45:00 -05:00
|
|
|
if extended_statuses.none?
|
2016-12-07 07:14:45 -05:00
|
|
|
core_status
|
2017-01-12 06:45:00 -05:00
|
|
|
else
|
2017-01-18 05:30:28 -05:00
|
|
|
compound_extended_status
|
2016-12-07 07:14:45 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def core_status
|
|
|
|
Gitlab::Ci::Status
|
2017-01-12 07:04:51 -05:00
|
|
|
.const_get(@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
|
|
|
|
|
2017-01-18 05:30:28 -05:00
|
|
|
def compound_extended_status
|
|
|
|
extended_statuses.inject(core_status) do |status, extended|
|
|
|
|
extended.new(status)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-12 06:45:00 -05:00
|
|
|
def extended_statuses
|
|
|
|
return @extended_statuses if defined?(@extended_statuses)
|
|
|
|
|
|
|
|
groups = self.class.extended_statuses.map do |group|
|
|
|
|
Array(group).find { |status| status.matches?(@subject, @user) }
|
2016-12-07 07:14:45 -05:00
|
|
|
end
|
2017-01-12 06:45:00 -05:00
|
|
|
|
|
|
|
@extended_statuses = groups.flatten.compact
|
2016-12-07 07:14:45 -05:00
|
|
|
end
|
2017-01-12 07:04:51 -05:00
|
|
|
|
|
|
|
def self.extended_statuses
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.common_helpers
|
|
|
|
Module.new
|
|
|
|
end
|
2016-12-07 07:14:45 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|