2016-06-17 06:06:48 -04:00
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
class Config
|
|
|
|
module Node
|
|
|
|
module Validators
|
2016-06-29 04:46:30 -04:00
|
|
|
class AllowedKeysValidator < ActiveModel::EachValidator
|
|
|
|
def validate_each(record, attribute, value)
|
|
|
|
if record.unknown_keys.any?
|
|
|
|
unknown_list = record.unknown_keys.join(', ')
|
|
|
|
record.errors.add(:config,
|
|
|
|
"contains unknown keys: #{unknown_list}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-17 06:06:48 -04:00
|
|
|
class ArrayOfStringsValidator < ActiveModel::EachValidator
|
|
|
|
include LegacyValidationHelpers
|
|
|
|
|
|
|
|
def validate_each(record, attribute, value)
|
|
|
|
unless validate_array_of_strings(value)
|
|
|
|
record.errors.add(attribute, 'should be an array of strings')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-06-17 08:51:39 -04:00
|
|
|
|
2016-06-24 03:49:54 -04:00
|
|
|
class BooleanValidator < ActiveModel::EachValidator
|
|
|
|
include LegacyValidationHelpers
|
|
|
|
|
|
|
|
def validate_each(record, attribute, value)
|
|
|
|
unless validate_boolean(value)
|
|
|
|
record.errors.add(attribute, 'should be a boolean value')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-24 02:58:09 -04:00
|
|
|
class KeyValidator < ActiveModel::EachValidator
|
|
|
|
include LegacyValidationHelpers
|
|
|
|
|
|
|
|
def validate_each(record, attribute, value)
|
|
|
|
unless validate_string(value)
|
|
|
|
record.errors.add(attribute, 'should be a string or symbol')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-21 05:43:32 -04:00
|
|
|
class TypeValidator < ActiveModel::EachValidator
|
2016-06-17 08:51:39 -04:00
|
|
|
def validate_each(record, attribute, value)
|
2016-06-21 05:43:32 -04:00
|
|
|
type = options[:with]
|
|
|
|
raise unless type.is_a?(Class)
|
|
|
|
|
|
|
|
unless value.is_a?(type)
|
|
|
|
record.errors.add(attribute, "should be a #{type.name}")
|
2016-06-17 08:51:39 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-06-22 05:22:53 -04:00
|
|
|
|
|
|
|
class VariablesValidator < ActiveModel::EachValidator
|
|
|
|
include LegacyValidationHelpers
|
|
|
|
|
|
|
|
def validate_each(record, attribute, value)
|
|
|
|
unless validate_variables(value)
|
|
|
|
record.errors.add(attribute, 'should be a hash of key value pairs')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-06-17 06:06:48 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|