Sha256: acd963b6372972dfecc0bd7cf8ce02c4fb8ac8672874f5042b4f2f5d16454575

Contents?: true

Size: 840 Bytes

Versions: 27

Compression:

Stored size: 840 Bytes

Contents

module Datadog
  module CI
    module Codeowners
      class Rule
        attr_reader :pattern, :owners

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

        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

        private

        def flags
          return ::File::FNM_PATHNAME if pattern.end_with?("#{::File::SEPARATOR}*")
          0
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
datadog-ci-1.14.0 lib/datadog/ci/codeowners/rule.rb
datadog-ci-1.13.0 lib/datadog/ci/codeowners/rule.rb
datadog-ci-1.12.0 lib/datadog/ci/codeowners/rule.rb
datadog-ci-1.11.0 lib/datadog/ci/codeowners/rule.rb
datadog-ci-1.10.0 lib/datadog/ci/codeowners/rule.rb
datadog-ci-1.9.0 lib/datadog/ci/codeowners/rule.rb
datadog-ci-1.8.1 lib/datadog/ci/codeowners/rule.rb
datadog-ci-1.8.0 lib/datadog/ci/codeowners/rule.rb
datadog-ci-1.7.0 lib/datadog/ci/codeowners/rule.rb
datadog-ci-1.6.0 lib/datadog/ci/codeowners/rule.rb
datadog-ci-1.5.0 lib/datadog/ci/codeowners/rule.rb
datadog-ci-1.4.1 lib/datadog/ci/codeowners/rule.rb
datadog-ci-1.4.0 lib/datadog/ci/codeowners/rule.rb
datadog-ci-1.3.0 lib/datadog/ci/codeowners/rule.rb
datadog-ci-1.2.0 lib/datadog/ci/codeowners/rule.rb
datadog-ci-1.1.0 lib/datadog/ci/codeowners/rule.rb
datadog-ci-1.0.1 lib/datadog/ci/codeowners/rule.rb
datadog-ci-1.0.0 lib/datadog/ci/codeowners/rule.rb
datadog-ci-1.0.0.beta6 lib/datadog/ci/codeowners/rule.rb
datadog-ci-1.0.0.beta3 lib/datadog/ci/codeowners/rule.rb