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 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# 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 # Every plugin must declare connection: explicitly — a connection name, # or `false` to opt out (e.g. the Sidekiq adapter reads Redis, not SQL). # This is enforced before validate_enablement! so a plugin's own role # check can't pre-empt the more actionable message. The value itself # (real name vs false) is validated by ConnectionRegistry and the # plugin's own validate_enablement!. unless opts.key?(:connection) raise ConfigurationError, "talk_to_your_app: plugin #{name.inspect} must declare a connection. " \ "Wire one with `config.plugin #{name.inspect}, connection: :your_connection`, " \ "or `connection: false` to opt out (no database access)." end plugin_class.validate_enablement!(opts) end end |