Module: CodeTeams

Extended by:
T::Sig
Defined in:
lib/code_teams/plugin.rb,
lib/code_teams.rb,
lib/code_teams/utils.rb,
lib/code_teams/plugins/identity.rb

Overview

typed: true

Defined Under Namespace

Modules: Plugins, Utils Classes: IncorrectPublicApiUsageError, Plugin, Team

Constant Summary collapse

UNKNOWN_TEAM_STRING =
'Unknown Team'

Class Method Summary collapse

Class Method Details

.allObject



21
22
23
24
# File 'lib/code_teams.rb', line 21

def self.all
  @all = T.let(@all, T.nilable(T::Array[Team]))
  @all ||= for_directory('config/teams')
end

.bust_caches!Object



68
69
70
71
72
73
# File 'lib/code_teams.rb', line 68

def self.bust_caches!
  @plugins_registered = false
  Plugin.bust_caches!
  @all = nil
  @index_by_name = nil
end

.find(name) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/code_teams.rb', line 27

def self.find(name)
  @index_by_name = T.let(@index_by_name, T.nilable(T::Hash[String, CodeTeams::Team]))
  @index_by_name ||= begin
    result = {}
    all.each { |t| result[t.name] = t }
    result
  end

  @index_by_name[name]
end

.for_directory(dir) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/code_teams.rb', line 39

def self.for_directory(dir)
  unless @plugins_registered
    Team.register_plugins
    @plugins_registered = true
  end

  Pathname.new(dir).glob('**/*.yml').map do |path|
    Team.from_yml(path.to_s)
  rescue Psych::SyntaxError
    raise IncorrectPublicApiUsageError, "The YML in #{path} has a syntax error!"
  end
end

.tag_value_for(string) ⇒ Object



60
61
62
# File 'lib/code_teams.rb', line 60

def self.tag_value_for(string)
  string.tr('&', ' ').gsub(/\s+/, '_').downcase
end

.validation_errors(teams) ⇒ Object



53
54
55
56
57
# File 'lib/code_teams.rb', line 53

def self.validation_errors(teams)
  Plugin.all_plugins.flat_map do |plugin|
    plugin.validation_errors(teams)
  end
end