Class: Hooks::Core::PluginLoader
- Inherits:
-
Object
- Object
- Hooks::Core::PluginLoader
- 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
-
.auth_plugins ⇒ Object
readonly
Returns the value of attribute auth_plugins.
-
.handler_plugins ⇒ Object
readonly
Returns the value of attribute handler_plugins.
-
.instrument_plugins ⇒ Object
readonly
Returns the value of attribute instrument_plugins.
-
.lifecycle_plugins ⇒ Object
readonly
Returns the value of attribute lifecycle_plugins.
Class Method Summary collapse
-
.clear_plugins ⇒ void
Clear all loaded plugins (for testing purposes).
-
.get_auth_plugin(plugin_name) ⇒ Class
Get auth plugin class by name.
-
.get_handler_plugin(handler_name) ⇒ Class
Get handler plugin class by name.
-
.get_instrument_plugin(instrument_type) ⇒ Object
Get instrument plugin instance by type.
-
.load_all_plugins(config) ⇒ void
Load all plugins at boot time.
Class Attribute Details
.auth_plugins ⇒ Object (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_plugins ⇒ Object (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_plugins ⇒ Object (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_plugins ⇒ Object (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_plugins ⇒ void
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
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
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
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
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 |