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)
|
2016-07-18 09:38:06 -04:00
|
|
|
unknown_keys = record.config.try(:keys).to_a - options[:in]
|
|
|
|
|
|
|
|
if unknown_keys.any?
|
|
|
|
record.errors.add(:config, 'contains unknown keys: ' +
|
|
|
|
unknown_keys.join(', '))
|
2016-06-29 04:46:30 -04:00
|
|
|
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-07-18 08:15:01 -04:00
|
|
|
class DurationValidator < ActiveModel::EachValidator
|
|
|
|
include LegacyValidationHelpers
|
|
|
|
|
|
|
|
def validate_each(record, attribute, value)
|
|
|
|
unless validate_duration(value)
|
|
|
|
record.errors.add(attribute, 'should be a duration')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-13 06:22:33 -04:00
|
|
|
class RequiredValidator < ActiveModel::EachValidator
|
2016-07-08 05:27:36 -04:00
|
|
|
def validate_each(record, attribute, value)
|
|
|
|
if value.nil?
|
|
|
|
raise Entry::InvalidError,
|
|
|
|
"Entry needs #{attribute} attribute set internally."
|
|
|
|
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
|