dry-system 1.2.5 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2025 Hanakai team
3
+ Copyright (c) 2015-2026 Hanakai team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
@@ -18,4 +18,3 @@ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
18
  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
19
  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
20
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
-
data/README.md CHANGED
@@ -1,10 +1,15 @@
1
1
  <!--- This file is synced from hanakai-rb/repo-sync -->
2
2
 
3
- [rubygem]: https://rubygems.org/gems/dry-system
4
3
  [actions]: https://github.com/dry-rb/dry-system/actions
4
+ [chat]: https://discord.gg/naQApPAsZB
5
+ [forum]: https://discourse.hanakai.org
6
+ [rubygem]: https://rubygems.org/gems/dry-system
5
7
 
6
8
  # dry-system [![Gem Version](https://badge.fury.io/rb/dry-system.svg)][rubygem] [![CI Status](https://github.com/dry-rb/dry-system/workflows/CI/badge.svg)][actions]
7
9
 
10
+ [![Forum](https://img.shields.io/badge/Forum-dc360f?logo=discourse&logoColor=white)][forum]
11
+ [![Chat](https://img.shields.io/badge/Chat-717cf8?logo=discord&logoColor=white)][chat]
12
+
8
13
  ## Links
9
14
 
10
15
  - [User documentation](https://dry-rb.org/gems/dry-system)
data/dry-system.gemspec CHANGED
@@ -17,19 +17,18 @@ Gem::Specification.new do |spec|
17
17
  spec.description = spec.summary
18
18
  spec.homepage = "https://dry-rb.org/gems/dry-system"
19
19
  spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-system.gemspec", "lib/**/*"]
20
- spec.bindir = "bin"
21
- spec.executables = []
20
+ spec.bindir = "exe"
21
+ spec.executables = Dir["exe/*"].map { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
24
  spec.extra_rdoc_files = ["README.md", "CHANGELOG.md", "LICENSE"]
25
25
 
26
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
27
26
  spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-system/blob/main/CHANGELOG.md"
28
27
  spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-system"
29
28
  spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-system/issues"
30
29
  spec.metadata["funding_uri"] = "https://github.com/sponsors/hanami"
31
30
 
32
- spec.required_ruby_version = ">= 3.1.0"
31
+ spec.required_ruby_version = ">= 3.3"
33
32
 
34
33
  spec.add_runtime_dependency "dry-auto_inject", "~> 1.1"
35
34
  spec.add_runtime_dependency "dry-configurable", "~> 1.3"
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "dry/configurable"
3
4
  require "dry/system/constants"
4
5
 
5
6
  module Dry
@@ -22,17 +22,24 @@ module Dry
22
22
  def initialize(container)
23
23
  @container = container
24
24
  @config = container.config
25
+ @loaded = Set.new
25
26
  end
26
27
 
27
28
  # @api private
28
29
  def finalize!
29
30
  ::Dir[registrations_dir.join(RB_GLOB)].each do |file|
30
- call(Identifier.new(File.basename(file, RB_EXT)))
31
+ ident = Identifier.new(File.basename(file, RB_EXT))
32
+
33
+ # Skip files already loaded during earlier stages of finalization, such as a provider
34
+ # resolving a component satisfied via a manifest. Since `#call` uses `load`, re-running
35
+ # here would attempt a duplicate registration and raise an error.
36
+ call(ident) unless @loaded.include?(ident.root_key)
31
37
  end
32
38
  end
33
39
 
34
40
  # @api private
35
41
  def call(component)
42
+ @loaded << component.root_key
36
43
  load(root.join(config.registrations_dir, "#{component.root_key}#{RB_EXT}"))
37
44
  end
38
45
 
@@ -17,13 +17,20 @@ module Dry
17
17
  end
18
18
 
19
19
  # @api private
20
- attr_reader :loader, :run_setup, :eager_load, :debug
20
+ attr_reader :loader, :run_setup, :eager_load, :enable_reloading, :debug
21
21
 
22
22
  # @api private
23
- def initialize(loader: nil, run_setup: true, eager_load: nil, debug: false)
23
+ def initialize(
24
+ loader: nil,
25
+ run_setup: true,
26
+ eager_load: nil,
27
+ enable_reloading: false,
28
+ debug: false
29
+ )
24
30
  @loader = loader || ::Zeitwerk::Loader.new
25
31
  @run_setup = run_setup
26
32
  @eager_load = eager_load
33
+ @enable_reloading = enable_reloading
27
34
  @debug = debug
28
35
  super()
29
36
  end
@@ -61,6 +68,10 @@ module Dry
61
68
  def configure_loader(loader, system)
62
69
  loader.tag = system.config.name || system.name unless loader.tag
63
70
  loader.inflector = CompatInflector.new(system.config)
71
+
72
+ # Must come before `loader.setup`, otherwise Zeitwerk raises.
73
+ loader.enable_reloading if enable_reloading
74
+
64
75
  loader.logger = method(:puts) if debug
65
76
  end
66
77
 
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "dry/configurable"
4
+
3
5
  module Dry
4
6
  module System
5
7
  class Provider
@@ -220,7 +220,7 @@ module Dry
220
220
  container
221
221
  else
222
222
  raise ArgumentError,
223
- "+namespace:+ must be true, string or symbol: #{namespace.inspect} given."
223
+ "+namespace:+ must be true, string or symbol: #{namespace.inspect} given."
224
224
  end
225
225
  end
226
226
 
@@ -34,6 +34,7 @@ module Dry
34
34
  def initialize(container)
35
35
  @providers = {}
36
36
  @container = container
37
+ @loaded = Set.new
37
38
  end
38
39
 
39
40
  # @api private
@@ -270,7 +271,7 @@ module Dry
270
271
  def load_provider(path)
271
272
  name = Pathname(path).basename(RB_EXT).to_s.to_sym
272
273
 
273
- Kernel.require path unless providers.key?(name)
274
+ load_provider_file(path) unless providers.key?(name)
274
275
 
275
276
  self
276
277
  end
@@ -278,7 +279,27 @@ module Dry
278
279
  def require_provider_file(name)
279
280
  provider_file = find_provider_file(name)
280
281
 
281
- Kernel.require provider_file if provider_file
282
+ load_provider_file(provider_file) if provider_file
283
+ end
284
+
285
+ # Evaluates a provider file, at most once for this registrar.
286
+ #
287
+ # Uses `load` rather than `require` so that a provider file is evaluated once per registrar
288
+ # rather than once per process. Evaluating the file adds its provider to this registrar alone.
289
+ # This allows for a container to be unloaded and reloaded, and its providers to be registered
290
+ # again.
291
+ #
292
+ # Tracks loaded files because `load`, unlike `require`, will evaluate a file more than once.
293
+ # A file registering a provider under some other name would otherwise be evaluated on every
294
+ # lookup of its own name, and raise {ProviderAlreadyRegisteredError} the second time.
295
+ def load_provider_file(path)
296
+ path = path.to_s
297
+
298
+ return if @loaded.include?(path)
299
+
300
+ @loaded << path
301
+
302
+ Kernel.load path
282
303
  end
283
304
 
284
305
  def find_provider_file(name)
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "dry/configurable"
4
+
3
5
  module Dry
4
6
  module System
5
7
  module ProviderSources
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module System
5
- VERSION = "1.2.5"
5
+ VERSION = "1.3.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-system
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.5
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hanakai team
8
- autorequire:
9
- bindir: bin
8
+ bindir: exe
10
9
  cert_chain: []
11
- date: 2025-11-30 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: dry-auto_inject
@@ -114,9 +113,9 @@ email:
114
113
  executables: []
115
114
  extensions: []
116
115
  extra_rdoc_files:
117
- - README.md
118
116
  - CHANGELOG.md
119
117
  - LICENSE
118
+ - README.md
120
119
  files:
121
120
  - CHANGELOG.md
122
121
  - LICENSE
@@ -168,12 +167,10 @@ homepage: https://dry-rb.org/gems/dry-system
168
167
  licenses:
169
168
  - MIT
170
169
  metadata:
171
- allowed_push_host: https://rubygems.org
172
170
  changelog_uri: https://github.com/dry-rb/dry-system/blob/main/CHANGELOG.md
173
171
  source_code_uri: https://github.com/dry-rb/dry-system
174
172
  bug_tracker_uri: https://github.com/dry-rb/dry-system/issues
175
173
  funding_uri: https://github.com/sponsors/hanami
176
- post_install_message:
177
174
  rdoc_options: []
178
175
  require_paths:
179
176
  - lib
@@ -181,15 +178,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
181
178
  requirements:
182
179
  - - ">="
183
180
  - !ruby/object:Gem::Version
184
- version: 3.1.0
181
+ version: '3.3'
185
182
  required_rubygems_version: !ruby/object:Gem::Requirement
186
183
  requirements:
187
184
  - - ">="
188
185
  - !ruby/object:Gem::Version
189
186
  version: '0'
190
187
  requirements: []
191
- rubygems_version: 3.3.27
192
- signing_key:
188
+ rubygems_version: 3.6.9
193
189
  specification_version: 4
194
190
  summary: Organize your code into reusable components
195
191
  test_files: []