Class: Gitlab::Ci::Config::External::Rules
- Inherits:
-
Object
- Object
- Gitlab::Ci::Config::External::Rules
- Defined in:
- lib/gitlab/ci/config/external/rules.rb
Defined Under Namespace
Classes: Result
Constant Summary collapse
Instance Method Summary collapse
- #evaluate(context) ⇒ Object
-
#initialize(rule_hashes) ⇒ Rules
constructor
A new instance of Rules.
Constructor Details
#initialize(rule_hashes) ⇒ Rules
Returns a new instance of Rules.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/gitlab/ci/config/external/rules.rb', line 10 def initialize(rule_hashes) return unless rule_hashes # We must compose the include rules entry here because included # files are expanded before `@root.compose!` runs in Ci::Config. rules_entry = Entry::Include::Rules.new(rule_hashes) rules_entry.compose! raise InvalidIncludeRulesError, "include:#{rules_entry.errors.first}" unless rules_entry.valid? @rule_list = Build::Rules::Rule.fabricate_list(rules_entry.value) end |
Instance Method Details
#evaluate(context) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/gitlab/ci/config/external/rules.rb', line 23 def evaluate(context) if @rule_list.nil? Result.new('always') elsif matched_rule = match_rule(context) Result.new(matched_rule.attributes[:when]) else Result.new('never') end rescue Build::Rules::Rule::Clause::ParseError => e raise InvalidIncludeRulesError, "include:#{e.}" end |