Extract CI entry config hash validation to validator

This commit is contained in:
Grzegorz Bizon 2016-06-17 14:51:39 +02:00
parent 2a87a55f87
commit 44b00a1ebb
3 changed files with 9 additions and 7 deletions

View File

@ -19,13 +19,7 @@ module Gitlab
included do
validations do
validate :hash_config_value
def hash_config_value
unless self.config.is_a?(Hash)
errors.add(:config, 'should be a configuration entry hash')
end
end
validates :config, hash: true
end
end

View File

@ -12,6 +12,14 @@ module Gitlab
end
end
end
class HashValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless value.is_a?(Hash)
record.errors.add(attribute, 'should be a configuration entry hash')
end
end
end
end
end
end