Class: Datadog::CI::Codeowners::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/ci/codeowners/rule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern, owners) ⇒ Rule

Returns a new instance of Rule.



7
8
9
10
# File 'lib/datadog/ci/codeowners/rule.rb', line 7

def initialize(pattern, owners)
  @pattern = pattern
  @owners = owners
end

Instance Attribute Details

#ownersObject (readonly)

Returns the value of attribute owners.



5
6
7
# File 'lib/datadog/ci/codeowners/rule.rb', line 5

def owners
  @owners
end

#patternObject (readonly)

Returns the value of attribute pattern.



5
6
7
# File 'lib/datadog/ci/codeowners/rule.rb', line 5

def pattern
  @pattern
end

Instance Method Details

#match?(file_path) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
22
# File 'lib/datadog/ci/codeowners/rule.rb', line 12

def match?(file_path)
  res = false
  # if pattern does not end with a separator or a wildcard, it could be either a directory or a file
  if !pattern.end_with?(::File::SEPARATOR, "*")
    directory_pattern = "#{pattern}#{::File::SEPARATOR}*"
    res ||= File.fnmatch?(directory_pattern, file_path, flags)
  end

  res ||= File.fnmatch?(pattern, file_path, flags)
  res
end