Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
solnic committed Jun 27, 2021
1 parent bd3a8c0 commit 285450d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/rom/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/rom/plugin_registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 285450d

Please sign in to comment.