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