gitlab-org--gitlab-foss/lib/gitlab/ci/build/rules/rule.rb
drew ac77bb9376 Introducing new Syntax for Ci::Build inclusion rules
- Added Gitlab::Ci::Config::Entry::Rules and Gitlab::Ci::Config::Entry::Rules:Rule
  to handle lists of Rule objects to be evalauted for job inclusion
- Added `if:` and `changes:` as available Rules::Rule::Clause classes
- Added Rules handling logic to Seed::Build#included? with extra specs
- Use DisallowedKeysValidator to mutually exclude rules: from only:/except: on job config
2019-08-20 20:03:43 +00:00

32 lines
695 B
Ruby

# frozen_string_literal: true
module Gitlab
module Ci
module Build
class Rules::Rule
attr_accessor :attributes
def self.fabricate_list(list)
list.map(&method(:new)) if list
end
def initialize(spec)
@clauses = []
@attributes = {}
spec.each do |type, value|
if clause = Clause.fabricate(type, value)
@clauses << clause
else
@attributes.merge!(type => value)
end
end
end
def matches?(pipeline, build)
@clauses.all? { |clause| clause.satisfied_by?(pipeline, build) }
end
end
end
end
end