Skip to content

Commit

Permalink
wip - initial work on attaching plugins to configuration notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
solnic committed Jun 26, 2021
1 parent 6abbc4e commit fb84f65
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
9 changes: 8 additions & 1 deletion lib/rom/components/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,14 @@ def adapter
)
end

# @api public
# @api private
def attach_plugins
plugins
.select { |plugin| plugin.attachable? }
.each { |plugin| plugin.attach_to(configuration) }
end

# @api private
def apply_plugins
plugins.each do |plugin|
plugin.apply_to(constant)
Expand Down
2 changes: 2 additions & 0 deletions lib/rom/components/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def key
#
# @api public
def build
attach_plugins

# TODO: this should become a built-in feature, no neeed to use a plugin
constant.use(:registry_reader, relations: components.relations.map(&:id).uniq)

Expand Down
10 changes: 10 additions & 0 deletions lib/rom/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ class Plugin
# @api private
option :type

# @api private
def attach_to(configuration)
# TODO: this is a noop for now
end

# @api private
def attachable?
mod.respond_to?(:subscribe)
end

# Apply this plugin to the target
#
# @param [Class,Object] target
Expand Down
6 changes: 5 additions & 1 deletion spec/shared/changeset/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
RSpec.shared_context "changeset / database setup" do
include_context "changeset / db_uri"

let(:configuration) { ROM::Configuration.new(:sql, db_uri) }
let(:configuration) do
ROM::Configuration.new(:sql, db_uri) do |config|
config.plugin(:sql, relation: :auto_restrictions)
end
end

let(:conn) { configuration.gateways[:default].connection }

Expand Down
5 changes: 4 additions & 1 deletion spec/shared/repository/database.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require "rom/sql"
RSpec.shared_context "repository / db_uri" do
let(:base_db_uri) do
ENV.fetch("BASE_DB_URI", "postgres@localhost/rom")
Expand All @@ -14,7 +15,9 @@
include_context "repository / db_uri"

let(:configuration) do
ROM::Configuration.new(:sql, db_uri)
ROM::Configuration.new(:sql, db_uri) do |config|
config.plugin(:sql, relation: :auto_restrictions)
end
end

let(:conn) do
Expand Down

0 comments on commit fb84f65

Please sign in to comment.