Class: CodeownerValidator::Lists::Whitelist

Inherits:
Object
  • Object
show all
Defined in:
lib/codeowner_validator/lists/whitelist.rb

Overview

Manage whitelist file reading

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename: nil, repo_path: nil) ⇒ Whitelist

Public: Initialized with a provided file

Parameters:

  • filename (String) (defaults to: nil)

    The filename to initialize the list with

  • repo_path (String) (defaults to: nil)

    The repository base path utilized for evaluation of a .gitignore



13
14
15
16
17
18
19
20
21
# File 'lib/codeowner_validator/lists/whitelist.rb', line 13

def initialize(filename: nil, repo_path: nil)
  @filename = filename
  @repo_path = repo_path

  # to avoid instance variable not initialized warnings
  @whitelist_file = nil
  @whitelist_file_paths = nil
  @git_ignore_file = nil
end

Instance Attribute Details

#repo_pathObject (readonly)

Returns the value of attribute repo_path.



7
8
9
# File 'lib/codeowner_validator/lists/whitelist.rb', line 7

def repo_path
  @repo_path
end

Instance Method Details

#exist?true

Public: Checks for existence configuration for the whitelist

Returns:

  • (true)

    if found; otherwise, <false>



26
27
28
# File 'lib/codeowner_validator/lists/whitelist.rb', line 26

def exist?
  !pathspec.empty?
end

#to_procObject

add a ‘to_proc` method that allows instances of this class to be passed as a block for easier chaining executions



43
44
45
# File 'lib/codeowner_validator/lists/whitelist.rb', line 43

def to_proc
  proc { |item| whitelisted?(item) }
end

#whitelisted?(filename) ⇒ true

Public: Returns <true> if the file supplied has been whitelisted; otherwise, <false>

Parameters:

  • filename (String)

    The file to evaluate if has been whitelisted

Returns:

  • (true)

    if the file supplied has been whitelisted; otherwise, <false>



34
35
36
37
38
39
# File 'lib/codeowner_validator/lists/whitelist.rb', line 34

def whitelisted?(filename)
  # if no items in the whitelist, assume all items are whitelisted
  return true if pathspec.empty?

  listed?(filename)
end