Class: Datadog::CI::Codeowners::Rule
- Inherits:
-
Object
- Object
- Datadog::CI::Codeowners::Rule
- Defined in:
- lib/datadog/ci/codeowners/rule.rb
Instance Attribute Summary collapse
-
#owners ⇒ Object
readonly
Returns the value of attribute owners.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
-
#initialize(pattern, owners) ⇒ Rule
constructor
A new instance of Rule.
- #match?(file_path) ⇒ Boolean
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
#owners ⇒ Object (readonly)
Returns the value of attribute owners.
5 6 7 |
# File 'lib/datadog/ci/codeowners/rule.rb', line 5 def owners @owners end |
#pattern ⇒ Object (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
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 |