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
|
|
|
|
|
|
|
|
validations do
|
2016-09-14 17:52:28 +00:00
|
|
|
validates :name, presence: true
|
2016-09-13 12:14:55 +00:00
|
|
|
|
2016-09-14 20:14:26 +00:00
|
|
|
validates :url,
|
|
|
|
length: { maximum: 255 },
|
|
|
|
allow_nil: true,
|
|
|
|
addressable_url: true
|
|
|
|
|
2016-09-13 12:14:55 +00:00
|
|
|
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-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
|
|
|
|
case
|
|
|
|
when string? then @config
|
|
|
|
when hash? then @config[:name]
|
2016-09-13 12:14:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-14 17:52:28 +00:00
|
|
|
def url
|
|
|
|
@config[:url] if hash?
|
|
|
|
end
|
|
|
|
|
2016-09-13 12:14:55 +00:00
|
|
|
def value
|
2016-09-14 17:52:28 +00:00
|
|
|
case
|
|
|
|
when string? then { name: @config }
|
|
|
|
when hash? then @config
|
|
|
|
end
|
2016-09-13 12:14:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|