Commit d9ca8401 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add first custom validator for new ci config

This follows a standard `ActiveModel` pattern of creating a custom
validators. We use `ActiveModel::EachValidator` here that reuses methods
provided by `LegacyValidationHelpers`.

We will remove `LegacyValidationHelpers` on some point in the future, at
the later stages of CI configuration refactoring. It may be possible
to rewrite custom validators to use format like:

`validates :config, array_of: String`
parent a9bd16bd
......@@ -14,15 +14,7 @@ module Gitlab
include Validatable
validations do
include LegacyValidationHelpers
validate :array_of_strings
def array_of_strings
unless validate_array_of_strings(self.config)
errors.add(:config, 'should be an array of strings')
end
end
validates :config, array_of_strings: true
end
def value
......
......@@ -4,6 +4,7 @@ module Gitlab
module Node
class Validator < SimpleDelegator
include ActiveModel::Validations
include Node::Validators
def initialize(node)
super(node)
......
module Gitlab
module Ci
class Config
module Node
module Validators
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
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment