debian-mirror-gitlab/lib/gitlab/ci/config/entry/validatable.rb

39 lines
965 B
Ruby
Raw Normal View History

2016-08-24 12:49:21 +05:30
module Gitlab
module Ci
class Config
2017-08-17 22:00:37 +05:30
module Entry
2016-08-24 12:49:21 +05:30
module Validatable
extend ActiveSupport::Concern
2018-03-17 18:26:18 +05:30
def self.included(node)
node.aspects.append -> do
@validator = self.class.validator.new(self)
@validator.validate(:new)
end
end
def errors
@validator.messages + descendants.flat_map(&:errors) # rubocop:disable Gitlab/ModuleWithInstanceVariables
end
2016-08-24 12:49:21 +05:30
class_methods do
def validator
2017-08-17 22:00:37 +05:30
@validator ||= Class.new(Entry::Validator).tap do |validator|
2016-09-13 17:45:13 +05:30
if defined?(@validations)
@validations.each { |rules| validator.class_eval(&rules) }
end
2016-08-24 12:49:21 +05:30
end
end
private
def validations(&block)
(@validations ||= []).append(block)
end
end
end
end
end
end
end