Skip to content

Commit

Permalink
Update AutoRegistrar to fit with dry-system 0.19
Browse files Browse the repository at this point in the history
  • Loading branch information
timriley committed May 24, 2021
1 parent 7dddae1 commit 792e065
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions lib/dry/effects/extensions/system.rb
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions spec/extensions/system/system/app.rb
Expand Up @@ -2,13 +2,17 @@

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')
# load_paths!('app')
# auto_register!('app')

boot(:persistence) do |container|
init() {}
Expand Down

0 comments on commit 792e065

Please sign in to comment.