From 285450dba3203ec472946a8803573a94bd7079fb Mon Sep 17 00:00:00 2001 From: Piotr Solnica Date: Sun, 27 Jun 2021 11:17:23 +0000 Subject: [PATCH] WIP --- lib/rom/configuration.rb | 14 ++++++-------- lib/rom/plugin_registry.rb | 5 +++++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/rom/configuration.rb b/lib/rom/configuration.rb index 84c44a76a..357c9b800 100644 --- a/lib/rom/configuration.rb +++ b/lib/rom/configuration.rb @@ -98,9 +98,12 @@ def finalize def attach_listeners # Anything can attach globally to certain events, including plugins, so here # we're making sure that only plugins that are enabled in thi configuration - # will be triggered - plugin_listeners = Notifications.listeners.slice(plugins.map(&:mod)) - global_listeners = Notifications.listeners.except(plugin_listeners.keys) + # will be + global_listeners, plugin_listeners = Notifications.listeners.to_a + .reject { |(src, *)| plugin_registry.mods.include?(src) }.to_h + + plugin_listeners = Notifications.listeners.to_a + .select { |(src, *)| plugins.map(&:mod).include?(src) }.to_h listeners.update(global_listeners).update(plugin_listeners) end @@ -110,11 +113,6 @@ def listeners notifications.listeners end - # @api private - def attach_plugins - plugins.select(&:attachable?).each { |plugin| plugin.attach_to(notifications) } - end - # Apply a plugin to the configuration # # @param [Mixed] plugin The plugin identifier, usually a Symbol diff --git a/lib/rom/plugin_registry.rb b/lib/rom/plugin_registry.rb index 3c62c32dd..20a747052 100644 --- a/lib/rom/plugin_registry.rb +++ b/lib/rom/plugin_registry.rb @@ -12,9 +12,13 @@ class PluginRegistry # @api private attr_reader :types + # @api private + attr_reader :mods + # @api private def initialize @types = ::Concurrent::Map.new + @mods = [] end # Register a plugin for future use @@ -27,6 +31,7 @@ def initialize # @option options [Symbol] :adapter (:default) which adapter this plugin # applies to. Leave blank for all adapters def register(name, mod, options = EMPTY_HASH) + mods << mod type(options.fetch(:type)).register(name, mod, options) end