Commit 8b185467 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Refactor only/except configuration policies

This commit refactors only/except policies so that these policies could
be self-contained. This also adds some changes to YAML configuration
library to provide more context to default entry value fabrication
process.
parent 3e9c9f97
......@@ -16,13 +16,6 @@ module Gitlab
dependencies before_script after_script variables
environment coverage retry parallel extends].freeze
DEFAULT_ONLY_POLICY = {
refs: %w(branches tags)
}.freeze
DEFAULT_EXCEPT_POLICY = {
}.freeze
validations do
validates :config, allowed_keys: ALLOWED_KEYS
validates :config, presence: true
......@@ -156,8 +149,8 @@ module Gitlab
services: services_value,
stage: stage_value,
cache: cache_value,
only: DEFAULT_ONLY_POLICY.deep_merge(only_value.to_h),
except: DEFAULT_EXCEPT_POLICY.deep_merge(except_value.to_h),
only: only_value,
except: except_value.to_h,
variables: variables_defined? ? variables_value : nil,
environment: environment_defined? ? environment_value : nil,
environment_name: environment_defined? ? environment_value[:name] : nil,
......
......@@ -14,7 +14,7 @@ module Gitlab
validates :config, key: true
end
def self.default
def self.default(**)
'default'
end
end
......
......@@ -64,7 +64,14 @@ module Gitlab
end
end
def self.default
def value
self.class.default(key: @key).yield_self do |default|
default.to_h.deep_merge(@subject.value.to_h)
end
end
def self.default(**attributes)
{ refs: %w(branches tags) } if attributes[:key] == :only
end
end
end
......
......@@ -82,9 +82,6 @@ module Gitlab
'retry config'
end
end
def self.default
end
end
end
end
......
......@@ -14,7 +14,7 @@ module Gitlab
validates :config, type: String
end
def self.default
def self.default(**)
'test'
end
end
......
......@@ -14,7 +14,7 @@ module Gitlab
validates :config, array_of_strings: true
end
def self.default
def self.default(**)
%w[build test deploy]
end
end
......
......@@ -14,7 +14,7 @@ module Gitlab
validates :config, variables: true
end
def self.default
def self.default(**)
{}
end
......
......@@ -53,10 +53,10 @@ module Gitlab
# If entry has a default value we fabricate concrete node
# with default value.
#
if @entry.default.nil?
if @entry.default(@attributes).nil?
fabricate(Entry::Undefined)
else
fabricate(@entry, @entry.default)
fabricate(@entry, @entry.default(@attributes))
end
end
......
......@@ -85,7 +85,7 @@ module Gitlab
"#<#{self.class.name} #{unspecified}{#{key}: #{val.inspect}}>"
end
def self.default
def self.default(**)
end
def self.aspects
......
......@@ -17,7 +17,7 @@ module Gitlab
entry = self.class.entry_class(strategy)
super(entry.new(config, metadata))
super(@subject = entry.new(config, metadata))
end
def self.strategy(name, **opts)
......@@ -37,6 +37,9 @@ module Gitlab
self::UnknownStrategy
end
end
def self.default(**)
end
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment