diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-01-28 12:23:03 +0100 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-02-19 17:24:03 +0100 |
commit | 9972abc2951e2d2c7c4c94189199234c39d25ceb (patch) | |
tree | 82b5d2794ca65a24d48ab154425f7d15fa2e8d46 | |
parent | c1affed19696ec9d78dbca3b5654d41e94282267 (diff) | |
download | gitlab-ce-9972abc2951e2d2c7c4c94189199234c39d25ceb.tar.gz |
Add methods to build eraseable component
-rw-r--r-- | app/models/ci/build.rb | 3 | ||||
-rw-r--r-- | app/models/concerns/compoundable.rb | 19 | ||||
-rw-r--r-- | lib/gitlab/ci/build/eraseable.rb | 25 |
3 files changed, 47 insertions, 0 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 623edd8bc57..a421aa64658 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -35,6 +35,9 @@ module Ci class Build < CommitStatus + include Compoundable + component :eraseable, Gitlab::Ci::Build::Eraseable + include Gitlab::Application.routes.url_helpers LAZY_ATTRIBUTES = ['trace'] diff --git a/app/models/concerns/compoundable.rb b/app/models/concerns/compoundable.rb new file mode 100644 index 00000000000..0cef53a1027 --- /dev/null +++ b/app/models/concerns/compoundable.rb @@ -0,0 +1,19 @@ +module Compoundable + extend ActiveSupport::Concern + + class_methods do + private + + def component(name, klass) + define_method(name) do + component_object = instance_variable_get("@#{name}") + return component_object if component_object + instance_variable_set("@#{name}", klass.new(self)) + end + + klass.instance_methods(false).each do |method| + delegate method, to: name + end + end + end +end diff --git a/lib/gitlab/ci/build/eraseable.rb b/lib/gitlab/ci/build/eraseable.rb new file mode 100644 index 00000000000..b7dbc9fb1a9 --- /dev/null +++ b/lib/gitlab/ci/build/eraseable.rb @@ -0,0 +1,25 @@ +module Gitlab + module Ci + module Build + class Eraseable + def initialize(build) + @build = build + end + + def erase! + raise NotImplementedError + end + + def erased? + @build.artifacts_file.exists? && @build.artifacts_metadata.exists? + end + + private + + def trace_file + raise NotImplementedError + end + end + end + end +end |