Fix CI job environment configuration entry class

This commit is contained in:
Grzegorz Bizon 2016-09-16 11:00:13 +02:00 committed by Kamil Trzcinski
parent 04b5695590
commit 3fbfc30f5e
1 changed files with 11 additions and 8 deletions

View File

@ -11,20 +11,22 @@ module Gitlab
ALLOWED_KEYS = %i[name url] ALLOWED_KEYS = %i[name url]
validations do validations do
validates :config, allowed_keys: ALLOWED_KEYS, if: :hash?
validates :name, presence: true validates :name, presence: true
validates :url,
length: { maximum: 255 },
allow_nil: true,
addressable_url: true
validate do validate do
unless hash? || string? unless hash? || string?
errors.add(:config, 'should be a hash or a string') errors.add(:config, 'should be a hash or a string')
end end
end end
with_options if: :hash? do
validates :config, allowed_keys: ALLOWED_KEYS
validates :url,
length: { maximum: 255 },
addressable_url: true,
allow_nil: true
end
end end
def hash? def hash?
@ -44,9 +46,10 @@ module Gitlab
end end
def value def value
case @config.type case @config
when String then { name: @config } when String then { name: @config }
when Hash then @config when Hash then @config
else {}
end end
end end
end end