2016-09-13 12:14:55 +00:00
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
class Config
|
|
|
|
module Node
|
|
|
|
##
|
2016-09-14 17:52:28 +00:00
|
|
|
# Entry that represents an environment.
|
2016-09-13 12:14:55 +00:00
|
|
|
#
|
|
|
|
class Environment < Entry
|
|
|
|
include Validatable
|
|
|
|
|
2016-09-14 21:00:15 +00:00
|
|
|
ALLOWED_KEYS = %i[name url]
|
|
|
|
|
2016-09-13 12:14:55 +00:00
|
|
|
validations do
|
|
|
|
validate do
|
2016-09-14 17:52:28 +00:00
|
|
|
unless hash? || string?
|
|
|
|
errors.add(:config, 'should be a hash or a string')
|
2016-09-13 12:14:55 +00:00
|
|
|
end
|
|
|
|
end
|
2016-09-16 09:00:13 +00:00
|
|
|
|
2016-09-16 09:25:37 +00:00
|
|
|
validates :name, presence: true
|
|
|
|
|
2016-09-16 09:00:13 +00:00
|
|
|
with_options if: :hash? do
|
|
|
|
validates :config, allowed_keys: ALLOWED_KEYS
|
|
|
|
|
|
|
|
validates :url,
|
|
|
|
length: { maximum: 255 },
|
|
|
|
addressable_url: true,
|
|
|
|
allow_nil: true
|
|
|
|
end
|
2016-09-14 17:52:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def hash?
|
|
|
|
@config.is_a?(Hash)
|
|
|
|
end
|
|
|
|
|
|
|
|
def string?
|
|
|
|
@config.is_a?(String)
|
|
|
|
end
|
2016-09-13 12:14:55 +00:00
|
|
|
|
2016-09-14 17:52:28 +00:00
|
|
|
def name
|
2016-09-15 19:59:01 +00:00
|
|
|
value[:name]
|
2016-09-13 12:14:55 +00:00
|
|
|
end
|
|
|
|
|
2016-09-14 17:52:28 +00:00
|
|
|
def url
|
2016-09-15 19:59:01 +00:00
|
|
|
value[:url]
|
2016-09-14 17:52:28 +00:00
|
|
|
end
|
|
|
|
|
2016-09-13 12:14:55 +00:00
|
|
|
def value
|
2016-09-16 09:00:13 +00:00
|
|
|
case @config
|
2016-09-14 21:00:15 +00:00
|
|
|
when String then { name: @config }
|
|
|
|
when Hash then @config
|
2016-09-16 09:00:13 +00:00
|
|
|
else {}
|
2016-09-14 17:52:28 +00:00
|
|
|
end
|
2016-09-13 12:14:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|