Class: Gitlab::Ci::Build::Rules::Rule::Clause::Changes

Inherits:
Gitlab::Ci::Build::Rules::Rule::Clause show all
Defined in:
lib/gitlab/ci/build/rules/rule/clause/changes.rb

Constant Summary

Constants inherited from Gitlab::Ci::Build::Rules::Rule::Clause

UnknownClauseError

Instance Method Summary collapse

Methods inherited from Gitlab::Ci::Build::Rules::Rule::Clause

fabricate

Constructor Details

#initialize(globs) ⇒ Changes

Returns a new instance of Changes.


7
8
9
# File 'lib/gitlab/ci/build/rules/rule/clause/changes.rb', line 7

def initialize(globs)
  @globs = Array(globs)
end

Instance Method Details

#expand_globs(context) ⇒ Object


22
23
24
25
26
27
28
# File 'lib/gitlab/ci/build/rules/rule/clause/changes.rb', line 22

def expand_globs(context)
  return @globs unless context

  @globs.map do |glob|
    ExpandVariables.expand_existing(glob, -> { context.variables_hash })
  end
end

#satisfied_by?(pipeline, context) ⇒ Boolean

Returns:

  • (Boolean)

11
12
13
14
15
16
17
18
19
20
# File 'lib/gitlab/ci/build/rules/rule/clause/changes.rb', line 11

def satisfied_by?(pipeline, context)
  return true unless pipeline&.modified_paths

  expanded_globs = expand_globs(context)
  pipeline.modified_paths.any? do |path|
    expanded_globs.any? do |glob|
      File.fnmatch?(glob, path, File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_EXTGLOB)
    end
  end
end