debian-mirror-gitlab/lib/gitlab/ci/status/factory.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
1.2 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module Gitlab
module Ci
module Status
class Factory
def initialize(subject, user)
@subject = subject
@user = user
2020-07-28 23:09:34 +05:30
@status = subject.status || ::Ci::HasStatus::DEFAULT_STATUS
2017-08-17 22:00:37 +05:30
end
def fabricate!
if extended_statuses.none?
core_status
else
compound_extended_status
end
end
def core_status
Gitlab::Ci::Status
2020-03-13 15:44:24 +05:30
.const_get(@status.to_s.camelize, false)
2017-08-17 22:00:37 +05:30
.new(@subject, @user)
.extend(self.class.common_helpers)
end
def compound_extended_status
extended_statuses.inject(core_status) do |status, extended|
extended.new(status)
end
end
def extended_statuses
return @extended_statuses if defined?(@extended_statuses)
2019-10-12 21:52:04 +05:30
@extended_statuses = self.class.extended_statuses.flat_map do |group|
2017-08-17 22:00:37 +05:30
Array(group).find { |status| status.matches?(@subject, @user) }
2019-10-12 21:52:04 +05:30
end.compact
2017-08-17 22:00:37 +05:30
end
def self.extended_statuses
[]
end
def self.common_helpers
Module.new
end
end
end
end
end