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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.1 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
module Gitlab
module Config
module Entry
module Validatable
extend ActiveSupport::Concern
def self.included(node)
2019-12-26 22:10:19 +05:30
node.with_aspect -> do
validate(:new)
2019-02-15 15:39:39 +05:30
end
end
2019-12-26 22:10:19 +05:30
def validator
@validator ||= self.class.validator.new(self)
end
def validate(context = nil)
validator.validate(context)
end
def compose!(deps = nil, &blk)
super(deps, &blk)
validate(:composed)
end
2019-02-15 15:39:39 +05:30
def errors
2019-12-26 22:10:19 +05:30
validator.messages + descendants.flat_map(&:errors)
2019-02-15 15:39:39 +05:30
end
class_methods do
def validator
@validator ||= Class.new(Entry::Validator).tap do |validator|
if defined?(@validations)
@validations.each { |rules| validator.class_eval(&rules) }
end
end
end
private
def validations(&block)
(@validations ||= []).append(block)
end
end
end
end
end
end