diff options
author | James Lopez <james@jameslopez.es> | 2016-06-16 13:04:00 +0200 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2016-06-16 13:04:00 +0200 |
commit | 778d72664f386dfee45dab171f137395739958f6 (patch) | |
tree | 7f2c902f4b97ac29aa97e96e877da201130a33b3 /lib/gitlab/ci/config/node/configurable.rb | |
parent | 452c076a34cc11cc97f4b1c3113e86ce4367e055 (diff) | |
parent | c369cc8bf42a680b2b0fc9721a9a7926dc5426f6 (diff) | |
download | gitlab-ce-778d72664f386dfee45dab171f137395739958f6.tar.gz |
Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ce into feature/project-exportfeature/project-export
# Conflicts:
# app/models/ci/pipeline.rb
Diffstat (limited to 'lib/gitlab/ci/config/node/configurable.rb')
-rw-r--r-- | lib/gitlab/ci/config/node/configurable.rb | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/lib/gitlab/ci/config/node/configurable.rb b/lib/gitlab/ci/config/node/configurable.rb new file mode 100644 index 00000000000..d60f87f3f94 --- /dev/null +++ b/lib/gitlab/ci/config/node/configurable.rb @@ -0,0 +1,61 @@ +module Gitlab + module Ci + class Config + module Node + ## + # This mixin is responsible for adding DSL, which purpose is to + # simplifly process of adding child nodes. + # + # This can be used only if parent node is a configuration entry that + # holds a hash as a configuration value, for example: + # + # job: + # script: ... + # artifacts: ... + # + module Configurable + extend ActiveSupport::Concern + + def allowed_nodes + self.class.allowed_nodes || {} + end + + private + + def prevalidate! + unless @value.is_a?(Hash) + @errors << 'should be a configuration entry with hash value' + end + end + + def create_node(key, factory) + factory.with(value: @value[key]) + factory.nullify! unless @value.has_key?(key) + factory.create! + end + + class_methods do + def allowed_nodes + Hash[@allowed_nodes.map { |key, factory| [key, factory.dup] }] + end + + private + + def allow_node(symbol, entry_class, metadata) + factory = Node::Factory.new(entry_class) + .with(description: metadata[:description]) + + define_method(symbol) do + raise Entry::InvalidError unless valid? + + @nodes[symbol].try(:value) + end + + (@allowed_nodes ||= {}).merge!(symbol => factory) + end + end + end + end + end + end +end |