Class: Codeowners::Ownership

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/codeowners/ownership.rb

Overview

The Ownership class represents an codeowners rule from a GitHub CODEOWNERS file. It includes methods to filter files matching the path expression and to check codeowners.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(glob, *owners) ⇒ Ownership

Initializes a new Ownership instance

Parameters:

  • glob (String)

    The file path pattern from the CODEOWNERS file

  • owners (Array<String>)

    The owners (team names) associated with the path expression



25
26
27
28
# File 'lib/codeowners/ownership.rb', line 25

def initialize(glob, *owners)
  @glob = Glob.new(glob)
  @owners = owners.map { |owner| Owner.new(owner) }
end

Instance Attribute Details

#globOwnership::Glob (readonly)

Returns The path expression from the CODEOWNERS file.

Returns:

  • (Ownership::Glob)

    The path expression from the CODEOWNERS file



16
17
18
# File 'lib/codeowners/ownership.rb', line 16

def glob
  @glob
end

#ownersArray<Codeowners::Owner> (readonly)

Returns The owners (team name) from the CODEOWNERS file.

Returns:



19
20
21
# File 'lib/codeowners/ownership.rb', line 19

def owners
  @owners
end

Instance Method Details

#owner?(owner_name) ⇒ Boolean

Checks if a given owner name matches the owner of this path expression

Parameters:

  • owner_name (String)

    the owner name to check

Returns:

  • (Boolean)

    true if the given owner name matches, false otherwise



34
35
36
# File 'lib/codeowners/ownership.rb', line 34

def owner?(owner_name)
  owners.any? { |owner| owner.match?(owner_name) }
end