Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to use latest dry-configurable and dry-system #83

Merged
merged 2 commits into from Jun 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
13 changes: 7 additions & 6 deletions lib/dry/effects/extensions/system.rb
Expand Up @@ -8,17 +8,18 @@ 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

class Container < ::Dry::System::Container
setting :auto_registrar, AutoRegistrar
config.auto_registrar = AutoRegistrar

def self.injector(effects: true, **kwargs)
if effects
Expand Down
11 changes: 6 additions & 5 deletions spec/extensions/system/system/app.rb
Expand Up @@ -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() {}
Expand Down