BigW Consortium Gitlab

validator.rb 869 Bytes
Newer Older
1 2 3 4 5
module Gitlab
  module Ci
    class Config
      module Node
        class Validator < SimpleDelegator
6
          include ActiveModel::Validations
7
          include Node::Validators
8

9 10
          def initialize(node)
            super(node)
11
            @node = node
12 13
          end

14
          def messages
15
            errors.full_messages.map do |error|
16
              "#{location} #{error}".downcase
17 18 19 20 21 22
            end
          end

          def self.name
            'Validator'
          end
23 24 25 26

          private

          def location
27
            predecessors = ancestors.map(&:key).compact
28 29 30 31
            predecessors.append(key_name).join(':')
          end

          def key_name
32
            if key.blank?
33 34 35 36
              @node.class.name.demodulize.underscore.humanize
            else
              key
            end
37
          end
38 39 40 41 42
        end
      end
    end
  end
end