Class: Gitlab::Ci::Build::Rules

Inherits:
Object
  • Object
show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/ci/build/rules.rb

Defined Under Namespace

Classes: Result, Rule

Instance Method Summary collapse

Methods included from Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(rule_hashes, default_when:) ⇒ Rules

Returns a new instance of Rules.


23
24
25
26
# File 'lib/gitlab/ci/build/rules.rb', line 23

def initialize(rule_hashes, default_when:)
  @rule_list    = Rule.fabricate_list(rule_hashes)
  @default_when = default_when
end

Instance Method Details

#evaluate(pipeline, context) ⇒ Object


28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gitlab/ci/build/rules.rb', line 28

def evaluate(pipeline, context)
  if @rule_list.nil?
    Result.new(@default_when)
  elsif matched_rule = match_rule(pipeline, context)
    Result.new(
      matched_rule.attributes[:when] || @default_when,
      matched_rule.attributes[:start_in],
      matched_rule.attributes[:allow_failure]
    )
  else
    Result.new('never')
  end
end