Class: Codeowners::Checker::CodeOwners

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/codeowners/checker/code_owners.rb

Overview

Manage CODEOWNERS file reading and re-writing.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_manager) ⇒ CodeOwners

Returns a new instance of CodeOwners.



14
15
16
# File 'lib/codeowners/checker/code_owners.rb', line 14

def initialize(file_manager)
  @file_manager = file_manager
end

Instance Attribute Details

#file_managerObject (readonly)

Returns the value of attribute file_manager.



12
13
14
# File 'lib/codeowners/checker/code_owners.rb', line 12

def file_manager
  @file_manager
end

Class Method Details

.filename(repo_dir) ⇒ Object



35
36
37
38
39
# File 'lib/codeowners/checker/code_owners.rb', line 35

def self.filename(repo_dir)
  directories = ['', '.github', 'docs', '.gitlab']
  paths = directories.map { |dir| File.join(repo_dir, dir, 'CODEOWNERS') }
  Dir.glob(paths).first || paths.first
end

Instance Method Details

#each(&block) ⇒ Object



27
28
29
# File 'lib/codeowners/checker/code_owners.rb', line 27

def each(&block)
  main_group.each(&block)
end

#filenameObject



41
42
43
# File 'lib/codeowners/checker/code_owners.rb', line 41

def filename
  @file_manager.filename
end

#main_groupObject



23
24
25
# File 'lib/codeowners/checker/code_owners.rb', line 23

def main_group
  @main_group ||= Group.parse(list)
end

#persist!Object



18
19
20
21
# File 'lib/codeowners/checker/code_owners.rb', line 18

def persist!
  file_manager.content = main_group.to_file
  file_manager.persist!
end

#to_contentObject



31
32
33
# File 'lib/codeowners/checker/code_owners.rb', line 31

def to_content
  main_group.to_content
end