Class: Codeowners::OwnerFinder
- Inherits:
-
Object
- Object
- Codeowners::OwnerFinder
- Defined in:
- lib/codeowners/owner_finder.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#find_owners_for_file(filepath:) ⇒ Array, <String>
Find the most likely owners of the file with the given filepath.
-
#find_ownership_for_file(filepath:) ⇒ Ownership
Find the most likely owners of the file with the given filepath.
-
#initialize(codeowners_file:) ⇒ OwnerFinder
constructor
A new instance of OwnerFinder.
Constructor Details
#initialize(codeowners_file:) ⇒ OwnerFinder
Returns a new instance of OwnerFinder.
13 14 15 |
# File 'lib/codeowners/owner_finder.rb', line 13 def initialize(codeowners_file:) @codeowners_file = codeowners_file end |
Class Method Details
.singleton ⇒ Object
9 10 11 |
# File 'lib/codeowners/owner_finder.rb', line 9 def self.singleton(...) @singleton ||= new(...) end |
Instance Method Details
#find_owners_for_file(filepath:) ⇒ Array, <String>
Find the most likely owners of the file with the given filepath. Returns the owner name as an Array of Strings (e.g. [“card-1-be”, “card-2-be”])
20 21 22 23 24 25 |
# File 'lib/codeowners/owner_finder.rb', line 20 def find_owners_for_file(filepath:) last_matching_ownership = find_ownership_for_file(filepath:) return [] if last_matching_ownership.nil? last_matching_ownership.owners.map(&:to_s) end |
#find_ownership_for_file(filepath:) ⇒ Ownership
Find the most likely owners of the file with the given filepath. Returns
29 30 31 32 33 |
# File 'lib/codeowners/owner_finder.rb', line 29 def find_ownership_for_file(filepath:) codeowners_file.ownerships_reversed.find do |ownership| ownership.glob_match?(filepath) end end |