Module: TalkToYourApp::PluginRegistry
- Defined in:
- lib/talk_to_your_app/plugin_registry.rb
Overview
Module-level registry of known plugins, keyed by name. Registration is explicit (‘TalkToYourApp.register_plugin(:db, Plugins::Db)`) rather than autoloaded by convention, so the contract is visible. Iteration follows registration (Hash insertion) order.
Class Method Summary collapse
- .[](name) ⇒ Object
- .register(name, plugin_class) ⇒ Object
- .registered?(name) ⇒ Boolean
- .registry ⇒ Object
-
.validate_enabled! ⇒ Object
Boot validation for the set of plugins the operator enabled: each must be registered, and any soft-dependency gem it declares must be loadable.
Class Method Details
.[](name) ⇒ Object
20 21 22 |
# File 'lib/talk_to_your_app/plugin_registry.rb', line 20 def [](name) registry[name.to_sym] end |
.register(name, plugin_class) ⇒ Object
15 16 17 18 |
# File 'lib/talk_to_your_app/plugin_registry.rb', line 15 def register(name, plugin_class) plugin_class.plugin_name = name.to_sym registry[name.to_sym] = plugin_class end |
.registered?(name) ⇒ Boolean
24 25 26 |
# File 'lib/talk_to_your_app/plugin_registry.rb', line 24 def registered?(name) registry.key?(name.to_sym) end |
.registry ⇒ Object
11 12 13 |
# File 'lib/talk_to_your_app/plugin_registry.rb', line 11 def registry @registry ||= {} end |
.validate_enabled! ⇒ Object
Boot validation for the set of plugins the operator enabled: each must be registered, and any soft-dependency gem it declares must be loadable. Connection requirements are validated separately by ConnectionRegistry.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/talk_to_your_app/plugin_registry.rb', line 31 def validate_enabled! TalkToYourApp.enabled_plugins.each do |name, plugin_class, opts| unless plugin_class raise ConfigurationError, "talk_to_your_app: plugin #{name.inspect} is enabled but no plugin is registered under that name." end if (req = plugin_class.required_gem) && !Object.const_defined?(req[:const]) raise ConfigurationError, "talk_to_your_app: Plugin #{name.inspect} requires the `#{req[:gem_name]}` gem in your Gemfile " \ "(constant #{req[:const]} is not defined)." end plugin_class.validate_enablement!(opts) end end |