summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/status/stage/factory.rb
blob: a2f7ad81d397443bef7a283ab7a9e1699682879c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module Gitlab
  module Ci
    module Status
      module Stage
        class Factory
          EXTENDED_STATUSES = []

          def initialize(stage)
            @stage = stage
            @status = stage.status || :created
          end

          def fabricate!
            if extended_status
              extended_status.new(core_status)
            else
              core_status
            end
          end

          private

          def core_status
            Gitlab::Ci::Status
              .const_get(@status.capitalize)
              .new(@stage)
              .extend(Status::Stage::Common)
          end

          def extended_status
            @extended ||= EXTENDED_STATUSES.find do |status|
              status.matches?(@stage)
            end
          end
        end
      end
    end
  end
end