Class: CodeTeams::Plugin

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers, T::Sig
Defined in:
lib/code_teams/plugin.rb

Overview

Plugins allow a client to add validation on custom keys in the team YML. For now, only a single plugin is allowed to manage validation on a top-level key. In the future we can think of allowing plugins to be gracefully merged with each other.

Direct Known Subclasses

CodeTeams::Plugins::Identity

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(team) ⇒ Plugin

Returns a new instance of Plugin.



16
17
18
# File 'lib/code_teams/plugin.rb', line 16

def initialize(team)
  @team = team
end

Class Method Details

.all_pluginsObject



37
38
39
40
41
# File 'lib/code_teams/plugin.rb', line 37

def self.all_plugins
  @all_plugins ||= T.let(@all_plugins, T.nilable(T::Array[T.class_of(Plugin)]))
  @all_plugins ||= []
  @all_plugins
end

.bust_caches!Object



78
79
80
# File 'lib/code_teams/plugin.rb', line 78

def self.bust_caches!
  all_plugins.each(&:clear_team_registry!)
end

.clear_team_registry!Object



83
84
85
# File 'lib/code_teams/plugin.rb', line 83

def self.clear_team_registry!
  @registry = nil
end

.data_accessor_name(key = default_data_accessor_name) ⇒ Object



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

def self.data_accessor_name(key = default_data_accessor_name)
  @data_accessor_name ||= key
end

.default_data_accessor_nameObject



26
27
28
29
# File 'lib/code_teams/plugin.rb', line 26

def self.default_data_accessor_name
  # e.g., MyNamespace::MyPlugin -> my_plugin
  Utils.underscore(Utils.demodulize(name))
end

.for(team) ⇒ Object



49
50
51
# File 'lib/code_teams/plugin.rb', line 49

def self.for(team)
  register_team(team)
end

.inherited(base) ⇒ Object

rubocop:disable Lint/MissingSuper



32
33
34
# File 'lib/code_teams/plugin.rb', line 32

def self.inherited(base) # rubocop:disable Lint/MissingSuper
  all_plugins << T.cast(base, T.class_of(Plugin))
end

.missing_key_error_message(team, key) ⇒ Object



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

def self.missing_key_error_message(team, key)
  "#{team.name} is missing required key `#{key}`"
end

.validation_errors(teams) ⇒ Object



44
45
46
# File 'lib/code_teams/plugin.rb', line 44

def self.validation_errors(teams)
  []
end