Class: Hooks::Core::PluginLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/hooks/core/plugin_loader.rb

Overview

Loads and caches all plugins (auth + handlers + lifecycle + instruments) at boot time

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.auth_pluginsObject (readonly)

Returns the value of attribute auth_plugins.



17
18
19
# File 'lib/hooks/core/plugin_loader.rb', line 17

def auth_plugins
  @auth_plugins
end

.handler_pluginsObject (readonly)

Returns the value of attribute handler_plugins.



17
18
19
# File 'lib/hooks/core/plugin_loader.rb', line 17

def handler_plugins
  @handler_plugins
end

.instrument_pluginsObject (readonly)

Returns the value of attribute instrument_plugins.



17
18
19
# File 'lib/hooks/core/plugin_loader.rb', line 17

def instrument_plugins
  @instrument_plugins
end

.lifecycle_pluginsObject (readonly)

Returns the value of attribute lifecycle_plugins.



17
18
19
# File 'lib/hooks/core/plugin_loader.rb', line 17

def lifecycle_plugins
  @lifecycle_plugins
end

Class Method Details

.clear_pluginsvoid

This method returns an undefined value.

Clear all loaded plugins (for testing purposes)



97
98
99
100
101
102
# File 'lib/hooks/core/plugin_loader.rb', line 97

def clear_plugins
  @auth_plugins = {}
  @handler_plugins = {}
  @lifecycle_plugins = []
  @instrument_plugins = { stats: nil, failbot: nil }
end

.get_auth_plugin(plugin_name) ⇒ Class

Get auth plugin class by name

Parameters:

  • plugin_name (String)

    Name of the auth plugin (e.g., “hmac”, “shared_secret”, “custom_auth”)

Returns:

  • (Class)

    The auth plugin class

Raises:

  • (StandardError)

    if plugin not found



51
52
53
54
55
56
57
58
59
60
# File 'lib/hooks/core/plugin_loader.rb', line 51

def get_auth_plugin(plugin_name)
  plugin_key = plugin_name.downcase
  plugin_class = @auth_plugins[plugin_key]

  unless plugin_class
    raise StandardError, "Auth plugin '#{plugin_name}' not found. Available plugins: #{@auth_plugins.keys.join(', ')}"
  end

  plugin_class
end

.get_handler_plugin(handler_name) ⇒ Class

Get handler plugin class by name

Parameters:

  • handler_name (String)

    Name of the handler in snake_case (e.g., “github_handler”, “team_1_handler”)

Returns:

  • (Class)

    The handler plugin class

Raises:

  • (StandardError)

    if handler not found



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/hooks/core/plugin_loader.rb', line 67

def get_handler_plugin(handler_name)
  # Convert snake_case to PascalCase for registry lookup
  pascal_case_name = handler_name.split("_").map(&:capitalize).join("")
  plugin_class = @handler_plugins[pascal_case_name]

  unless plugin_class
    raise StandardError, "Handler plugin '#{handler_name}' not found. Available handlers: #{@handler_plugins.keys.join(', ')}"
  end

  plugin_class
end

.get_instrument_plugin(instrument_type) ⇒ Object

Get instrument plugin instance by type

Parameters:

  • instrument_type (Symbol)

    Type of instrument (:stats or :failbot)

Returns:

  • (Object)

    The instrument plugin instance

Raises:

  • (StandardError)

    if instrument not found



84
85
86
87
88
89
90
91
92
# File 'lib/hooks/core/plugin_loader.rb', line 84

def get_instrument_plugin(instrument_type)
  instrument_instance = @instrument_plugins[instrument_type]

  unless instrument_instance
    raise StandardError, "Instrument plugin '#{instrument_type}' not found"
  end

  instrument_instance
end

.load_all_plugins(config) ⇒ void

This method returns an undefined value.

Load all plugins at boot time

Parameters:

  • config (Hash)

    Global configuration containing plugin directories



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/hooks/core/plugin_loader.rb', line 23

def load_all_plugins(config)
  # Clear existing registries
  @auth_plugins = {}
  @handler_plugins = {}
  @lifecycle_plugins = []
  @instrument_plugins = { stats: nil, failbot: nil }

  # Load built-in plugins first
  load_builtin_plugins

  # Load custom plugins if directories are configured
  load_custom_auth_plugins(config[:auth_plugin_dir]) if config[:auth_plugin_dir]
  load_custom_handler_plugins(config[:handler_plugin_dir]) if config[:handler_plugin_dir]
  load_custom_lifecycle_plugins(config[:lifecycle_plugin_dir]) if config[:lifecycle_plugin_dir]
  load_custom_instrument_plugins(config[:instruments_plugin_dir]) if config[:instruments_plugin_dir]

  # Load default instruments if no custom ones were loaded
  load_default_instruments

  # Log loaded plugins
  log_loaded_plugins
end