Commit e6e812e2 authored by Fabio Pitino's avatar Fabio Pitino Committed by Kamil Trzciński

Remove `Configurable#helpers` method

Simplify configurations by defining helpers by default
parent 8da519a8
......@@ -21,8 +21,6 @@ module Gitlab
entry :terminal, Entry::Terminal,
description: 'Configuration of the webide terminal.'
helpers :terminal
attributes :terminal
end
end
......
......@@ -42,8 +42,6 @@ module Gitlab
entry :variables, ::Gitlab::Ci::Config::Entry::Variables,
description: 'Environment variables available for this job.'
helpers :before_script, :script, :image, :variables, :services
attributes :tags
def value
......
......@@ -44,8 +44,6 @@ module Gitlab
end
end
helpers :reports
def value
@config[:reports] = reports_value if @config.key?(:reports)
@config
......
......@@ -49,8 +49,6 @@ module Gitlab
description: 'Environment variables available for this job.',
inherit: false
helpers :trigger, :needs, :variables
attributes :when, :allow_failure
def self.matching?(name, config)
......
......@@ -28,8 +28,6 @@ module Gitlab
entry :paths, Entry::Paths,
description: 'Specify which paths should be cached across builds.'
helpers :key
attributes :policy
def value
......
......@@ -61,8 +61,6 @@ module Gitlab
description: 'Default artifacts.',
inherit: false
helpers :before_script, :image, :services, :after_script, :cache
private
def overwrite_entry(deps, key, current_entry)
......
......@@ -128,11 +128,6 @@ module Gitlab
description: 'This job will produce a release.',
inherit: false
helpers :before_script, :script, :type, :after_script,
:cache, :image, :services, :variables,
:artifacts, :environment, :coverage, :retry,
:needs, :interruptible, :release, :tags
attributes :script, :tags, :allow_failure, :when, :dependencies,
:needs, :retry, :parallel, :start_in,
:interruptible, :timeout, :resource_group, :release
......
......@@ -54,8 +54,6 @@ module Gitlab
allowed_when: %w[on_success on_failure always never manual delayed].freeze
}
helpers :stage, :only, :except, :rules
attributes :extends, :rules
end
......
......@@ -33,8 +33,6 @@ module Gitlab
validates :description, type: String, presence: true
end
helpers :assets
def value
@config[:assets] = assets_value if @config.key?(:assets)
@config
......
......@@ -23,8 +23,6 @@ module Gitlab
validates :links, array_of_hashes: true, presence: true
end
helpers :links
def value
@config[:links] = links_value if @config.key?(:links)
@config
......
......@@ -67,9 +67,7 @@ module Gitlab
entry :workflow, Entry::Workflow,
description: 'List of evaluable rules to determine Pipeline status'
helpers :default, :stages, :types, :variables, :workflow
helpers :jobs, dynamic: true
dynamic_helpers :jobs
delegate :before_script_value,
:image_value,
......
......@@ -7,8 +7,13 @@ module Gitlab
##
# Entry that represents a configuration of Docker service.
#
class Service < Image
# TODO: remove duplication with Image superclass by defining a common
# Imageable concern.
# https://gitlab.com/gitlab-org/gitlab/issues/208774
class Service < ::Gitlab::Config::Entry::Node
include ::Gitlab::Config::Entry::Validatable
include ::Gitlab::Config::Entry::Attributable
include ::Gitlab::Config::Entry::Configurable
ALLOWED_KEYS = %i[name entrypoint command alias ports].freeze
......@@ -16,9 +21,9 @@ module Gitlab
validates :config, hash_or_string: true
validates :config, allowed_keys: ALLOWED_KEYS
validates :config, disallowed_keys: %i[ports], unless: :with_image_ports?
validates :name, type: String, presence: true
validates :entrypoint, array_of_strings: true, allow_nil: true
validates :command, array_of_strings: true, allow_nil: true
validates :alias, type: String, allow_nil: true
validates :alias, type: String, presence: true, unless: ->(record) { record.ports.blank? }
......@@ -27,6 +32,8 @@ module Gitlab
entry :ports, Entry::Ports,
description: 'Ports used to expose the service'
attributes :ports
def alias
value[:alias]
end
......@@ -34,6 +41,29 @@ module Gitlab
def command
value[:command]
end
def name
value[:name]
end
def entrypoint
value[:entrypoint]
end
def value
return { name: @config } if string?
return @config if hash?
{}
end
def with_image_ports?
opt(:with_image_ports)
end
def skip_config_hash_validation?
true
end
end
end
end
......
......@@ -75,7 +75,8 @@ module Gitlab
# rubocop: disable CodeReuse/ActiveRecord
def entry(key, entry, description: nil, default: nil, inherit: nil, reserved: nil, metadata: {})
raise ArgumentError, "Entry #{key} already defined" if @nodes.to_h[key.to_sym]
entry_name = key.to_sym
raise ArgumentError, "Entry #{key} already defined" if @nodes.to_h[entry_name]
factory = ::Gitlab::Config::Entry::Factory.new(entry)
.with(description: description)
......@@ -84,10 +85,17 @@ module Gitlab
.with(reserved: reserved)
.metadata(metadata)
(@nodes ||= {}).merge!(key.to_sym => factory)
@nodes ||= {}
@nodes[entry_name] = factory
helpers(entry_name)
end
# rubocop: enable CodeReuse/ActiveRecord
def dynamic_helpers(*nodes)
helpers(*nodes, dynamic: true)
end
def helpers(*nodes, dynamic: false)
nodes.each do |symbol|
if method_defined?("#{symbol}_defined?") || method_defined?("#{symbol}_value")
......
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