debian-mirror-gitlab/lib/gitlab/ci/config/entry/variables.rb

50 lines
1.2 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2016-08-24 12:49:21 +05:30
module Gitlab
module Ci
class Config
2017-08-17 22:00:37 +05:30
module Entry
2016-08-24 12:49:21 +05:30
##
# Entry that represents environment variables.
#
2019-02-15 15:39:39 +05:30
class Variables < ::Gitlab::Config::Entry::Node
include ::Gitlab::Config::Entry::Validatable
2016-08-24 12:49:21 +05:30
2021-01-03 14:25:43 +05:30
ALLOWED_VALUE_DATA = %i[value description].freeze
2016-08-24 12:49:21 +05:30
validations do
2021-02-22 17:27:13 +05:30
validates :config, variables: { allowed_value_data: ALLOWED_VALUE_DATA }, if: :use_value_data?
validates :config, variables: true, unless: :use_value_data?
2021-01-03 14:25:43 +05:30
end
def value
2021-04-29 21:17:54 +05:30
@config.to_h { |key, value| [key.to_s, expand_value(value)[:value]] }
2016-08-24 12:49:21 +05:30
end
2019-03-02 22:35:43 +05:30
def self.default(**)
2016-08-24 12:49:21 +05:30
{}
end
2017-09-10 17:25:29 +05:30
2021-01-03 14:25:43 +05:30
def value_with_data
2021-04-29 21:17:54 +05:30
@config.to_h { |key, value| [key.to_s, expand_value(value)] }
2021-01-03 14:25:43 +05:30
end
2021-02-22 17:27:13 +05:30
def use_value_data?
opt(:use_value_data)
end
2021-01-03 14:25:43 +05:30
private
def expand_value(value)
if value.is_a?(Hash)
{ value: value[:value].to_s, description: value[:description] }
else
{ value: value.to_s, description: nil }
end
2017-09-10 17:25:29 +05:30
end
2016-08-24 12:49:21 +05:30
end
end
end
end
end