From 7dddae19b95c5b560ede5983cfc2cc17bd358306 Mon Sep 17 00:00:00 2001 From: Tim Riley Date: Mon, 24 May 2021 21:55:23 +1000 Subject: [PATCH 1/2] Set config value rather than redefining setting This means we don't need to worry about updating to the latest dry-configurable `setting` API, which requires the `default:` keyword arg for default values. --- lib/dry/effects/extensions/system.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/dry/effects/extensions/system.rb b/lib/dry/effects/extensions/system.rb index df40338..07baab3 100644 --- a/lib/dry/effects/extensions/system.rb +++ b/lib/dry/effects/extensions/system.rb @@ -18,7 +18,7 @@ def call(dir) end class Container < ::Dry::System::Container - setting :auto_registrar, AutoRegistrar + config.auto_registrar = AutoRegistrar def self.injector(effects: true, **kwargs) if effects From f3a5b2fe67efdd0bf9ff36198b1d40326d647e1a Mon Sep 17 00:00:00 2001 From: Tim Riley Date: Mon, 24 May 2021 22:01:52 +1000 Subject: [PATCH 2/2] Update AutoRegistrar to fit with dry-system 0.19 --- Gemfile | 3 ++- lib/dry/effects/extensions/system.rb | 11 ++++++----- spec/extensions/system/system/app.rb | 11 ++++++----- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Gemfile b/Gemfile index d51209b..4b2fddd 100644 --- a/Gemfile +++ b/Gemfile @@ -9,7 +9,8 @@ gemspec group :test do gem "activesupport" gem "dry-auto_inject", require: false - gem "dry-system" + gem "dry-configurable", github: "dry-rb/dry-configurable" + gem "dry-system", "~> 0.19.0" end group :tools do diff --git a/lib/dry/effects/extensions/system.rb b/lib/dry/effects/extensions/system.rb index 07baab3..2de1b7d 100644 --- a/lib/dry/effects/extensions/system.rb +++ b/lib/dry/effects/extensions/system.rb @@ -8,11 +8,12 @@ module Dry module Effects module System class AutoRegistrar < ::Dry::System::AutoRegistrar - def call(dir) - super do |config| - config.memoize = true - config.instance { |c| c.instance.freeze } - yield(config) if block_given? + # Always memoize and freeze registered components + def call(component_dir) + components(component_dir).each do |component| + next unless register_component?(component) + + container.register(component.key, memoize: true) { component.instance.freeze } end end end diff --git a/spec/extensions/system/system/app.rb b/spec/extensions/system/system/app.rb index c07c642..0e10db1 100644 --- a/spec/extensions/system/system/app.rb +++ b/spec/extensions/system/system/app.rb @@ -2,14 +2,15 @@ module Test class App < Dry::Effects::System::Container - config.root = ::File.expand_path(::File.join(__dir__, '..')) - config.default_namespace = 'test' + configure do |config| + config.root = ::File.expand_path(::File.join(__dir__, "..")) + config.component_dirs.default_namespace = "test" + config.component_dirs.add_to_load_path = true + config.component_dirs.add "app" + end Import = injector - load_paths!('app') - auto_register!('app') - boot(:persistence) do |container| init() {} start() {}