diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-12-07 15:14:45 +0300 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-12-07 15:14:45 +0300 |
commit | 93c72e0f71919968972e874519e01370edcce022 (patch) | |
tree | 7c57a3e0239db10e413add2b869f66d8eeda72ef /lib/gitlab | |
parent | c4e46c5740426f656c019b51b9731ea8a16f42d0 (diff) |
Add Ci::Status::Factory
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/ci/status/factory.rb | 43 | ||||
-rw-r--r-- | lib/gitlab/ci/status/pipeline/factory.rb | 30 | ||||
-rw-r--r-- | lib/gitlab/ci/status/stage/factory.rb | 28 |
3 files changed, 50 insertions, 51 deletions
diff --git a/lib/gitlab/ci/status/factory.rb b/lib/gitlab/ci/status/factory.rb new file mode 100644 index 00000000000..b2f896f2211 --- /dev/null +++ b/lib/gitlab/ci/status/factory.rb @@ -0,0 +1,43 @@ +module Gitlab + module Ci + module Status + class Factory + attr_reader :subject + + def initialize(subject) + @subject = subject + end + + def fabricate! + if extended_status + extended_status.new(core_status) + else + core_status + end + end + + private + + def subject_status + @subject_status ||= subject.status + end + + def core_status + Gitlab::Ci::Status + .const_get(subject_status.capitalize) + .new(subject) + end + + def extended_status + @extended ||= extended_statuses.find do |status| + status.matches?(subject) + end + end + + def extended_statuses + [] + end + end + end + end +end diff --git a/lib/gitlab/ci/status/pipeline/factory.rb b/lib/gitlab/ci/status/pipeline/factory.rb index 71d27bf7cf5..4ac4ec671d0 100644 --- a/lib/gitlab/ci/status/pipeline/factory.rb +++ b/lib/gitlab/ci/status/pipeline/factory.rb @@ -2,35 +2,15 @@ module Gitlab module Ci module Status module Pipeline - class Factory - EXTENDED_STATUSES = [Pipeline::SuccessWithWarnings] - - def initialize(pipeline) - @pipeline = pipeline - @status = pipeline.status || :created - end - - def fabricate! - if extended_status - extended_status.new(core_status) - else - core_status - end - end - + class Factory < Status::Factory private - def core_status - Gitlab::Ci::Status - .const_get(@status.capitalize) - .new(@pipeline) - .extend(Status::Pipeline::Common) + def extended_statuses + [Pipeline::SuccessWithWarnings] end - def extended_status - @extended ||= EXTENDED_STATUSES.find do |status| - status.matches?(@pipeline) - end + def core_status + super.extend(Status::Pipeline::Common) end end end diff --git a/lib/gitlab/ci/status/stage/factory.rb b/lib/gitlab/ci/status/stage/factory.rb index a2f7ad81d39..c6522d5ada1 100644 --- a/lib/gitlab/ci/status/stage/factory.rb +++ b/lib/gitlab/ci/status/stage/factory.rb @@ -2,35 +2,11 @@ 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 - + class Factory < Status::Factory 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 + super.extend(Status::Stage::Common) end end end |