dry-system 1.2.4 → 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-2023 dry-rb 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
data/README.md CHANGED
@@ -1,23 +1,22 @@
1
- <!--- this file is synced from dry-rb/template-gem project -->
1
+ <!--- This file is synced from hanakai-rb/repo-sync -->
2
2
 
3
- [gem]: 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
- # dry-system [![Gem Version](https://badge.fury.io/rb/dry-system.svg)][gem] [![CI Status](https://github.com/dry-rb/dry-system/workflows/CI/badge.svg)][actions]
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
 
8
- ## Links
9
-
10
- * [User documentation](https://dry-rb.org/gems/dry-system)
11
- * [API documentation](http://rubydoc.info/gems/dry-system)
12
- * [Forum](https://discourse.dry-rb.org)
13
-
14
- ## Supported Ruby versions
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]
15
12
 
16
- This library officially supports the following Ruby versions:
13
+ ## Links
17
14
 
18
- * MRI `>= 3.1`
19
- * jruby `>= 9.4` (not tested on CI)
15
+ - [User documentation](https://dry-rb.org/gems/dry-system)
16
+ - [API documentation](http://rubydoc.info/gems/dry-system)
17
+ - [Forum](https://discourse.dry-rb.org)
20
18
 
21
19
  ## License
22
20
 
23
21
  See `LICENSE` file.
22
+
data/dry-system.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # this file is synced from dry-rb/template-gem project
3
+ # This file is synced from hanakai-rb/repo-sync. To update it, edit repo-sync.yml.
4
4
 
5
5
  lib = File.expand_path("lib", __dir__)
6
6
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
@@ -8,8 +8,8 @@ require "dry/system/version"
8
8
 
9
9
  Gem::Specification.new do |spec|
10
10
  spec.name = "dry-system"
11
- spec.authors = ["Piotr Solnica"]
12
- spec.email = ["piotr.solnica@gmail.com"]
11
+ spec.authors = ["Hanakai team"]
12
+ spec.email = ["info@hanakai.org"]
13
13
  spec.license = "MIT"
14
14
  spec.version = Dry::System::VERSION.dup
15
15
 
@@ -17,21 +17,25 @@ 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
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
25
- spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-system/blob/main/CHANGELOG.md"
26
- spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-system"
27
- spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-system/issues"
28
- spec.metadata["rubygems_mfa_required"] = "true"
24
+ spec.extra_rdoc_files = ["README.md", "CHANGELOG.md", "LICENSE"]
29
25
 
30
- spec.required_ruby_version = ">= 3.1"
26
+ spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-system/blob/main/CHANGELOG.md"
27
+ spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-system"
28
+ spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-system/issues"
29
+ spec.metadata["funding_uri"] = "https://github.com/sponsors/hanami"
31
30
 
32
- # to update dependencies edit project.yml
33
- spec.add_dependency "dry-auto_inject", "~> 1.1"
34
- spec.add_dependency "dry-configurable", "~> 1.3"
35
- spec.add_dependency "dry-core", "~> 1.1"
36
- spec.add_dependency "dry-inflector", "~> 1.1"
31
+ spec.required_ruby_version = ">= 3.3"
32
+
33
+ spec.add_runtime_dependency "dry-auto_inject", "~> 1.1"
34
+ spec.add_runtime_dependency "dry-configurable", "~> 1.3"
35
+ spec.add_runtime_dependency "dry-core", "~> 1.1"
36
+ spec.add_runtime_dependency "dry-inflector", "~> 1.1"
37
+ spec.add_development_dependency "bundler"
38
+ spec.add_development_dependency "rake"
39
+ spec.add_development_dependency "rspec"
37
40
  end
41
+
@@ -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
@@ -64,8 +64,6 @@ module Dry
64
64
  #
65
65
  # @see memoize=
66
66
 
67
- # rubocop:disable Layout/LineLength
68
-
69
67
  # @!method namespaces
70
68
  #
71
69
  # Returns the default configured namespaces for all added component dirs
@@ -89,8 +87,6 @@ module Dry
89
87
  #
90
88
  # @see add_to_load_path=
91
89
 
92
- # rubocop:enable Layout/LineLength
93
-
94
90
  # @!endgroup
95
91
 
96
92
  # A ComponentDir for configuring the default values to apply to all added
@@ -110,7 +106,7 @@ module Dry
110
106
 
111
107
  # @api private
112
108
  def initialize_copy(source)
113
- @dirs = source.dirs.to_h { |path, dir| [path, dir.dup] }
109
+ @dirs = source.dirs.transform_values(&:dup)
114
110
  @defaults = source.defaults.dup
115
111
  end
116
112
 
@@ -48,8 +48,6 @@ module Dry
48
48
  namespaces[Namespace::ROOT_PATH]
49
49
  end
50
50
 
51
- # rubocop:disable Layout/LineLength
52
-
53
51
  # Adds a component dir namespace
54
52
  #
55
53
  # A namespace encompasses a given sub-directory of the component dir, and
@@ -102,8 +100,6 @@ module Dry
102
100
  namespaces[path] = Namespace.new(path: path, key: key, const: const)
103
101
  end
104
102
 
105
- # rubocop:enable Layout/LineLength
106
-
107
103
  # Adds a root component dir namespace
108
104
  #
109
105
  # @see #add
@@ -183,8 +183,6 @@ module Dry
183
183
  self
184
184
  end
185
185
 
186
- # rubocop:disable Layout/LineLength
187
-
188
186
  # @overload register_provider(name, namespace: nil, from: nil, source: nil, if: true, &block)
189
187
  # Registers a provider and its lifecycle hooks
190
188
  #
@@ -274,8 +272,6 @@ module Dry
274
272
  providers.register_provider(...)
275
273
  end
276
274
 
277
- # rubocop:enable Layout/LineLength
278
-
279
275
  # Return if a container was finalized
280
276
  #
281
277
  # @return [TrueClass, FalseClass]
@@ -64,12 +64,12 @@ module Dry
64
64
  inflector = component.inflector
65
65
  const_name = inflector.camelize(component.const_path)
66
66
  inflector.constantize(const_name)
67
- rescue NameError => e
67
+ rescue NameError => exception
68
68
  # Ensure it's this component's constant, not any other NameError within the component
69
- if e.message =~ /#{const_name}( |\n|$)/
70
- raise ComponentNotLoadableError.new(component, e)
69
+ if exception.message =~ /#{const_name}( |\n|$)/
70
+ raise ComponentNotLoadableError.new(component, exception)
71
71
  else
72
- raise e
72
+ raise exception
73
73
  end
74
74
  end
75
75
 
@@ -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
 
@@ -28,12 +28,12 @@ module Dry
28
28
  monitored_methods(monitored_methods)
29
29
 
30
30
  monitored_methods.each do |meth|
31
- define_method(meth) do |*args, &block|
31
+ define_method(meth) do |*args, **kwargs, &block|
32
32
  object = __getobj__
33
- opts = {target: key, object: object, method: meth, args: args}
33
+ opts = {target: key, object: object, method: meth, args: args, kwargs: kwargs}
34
34
 
35
35
  __notifications__.instrument(:monitoring, opts) do
36
- object.public_send(meth, *args, &block)
36
+ object.public_send(meth, *args, **kwargs, &block)
37
37
  end
38
38
  end
39
39
  end
@@ -40,8 +40,8 @@ module Dry
40
40
  def load_dependency(dependency, gem)
41
41
  Kernel.require dependency
42
42
  Plugins.loaded_dependencies << dependency.to_s
43
- rescue LoadError => e
44
- raise PluginDependencyMissing.new(name, e.message, gem)
43
+ rescue LoadError => exception
44
+ raise PluginDependencyMissing.new(name, exception.message, gem)
45
45
  end
46
46
 
47
47
  # @api private
@@ -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
@@ -125,7 +126,7 @@ module Dry
125
126
  # @return [Array<Pathname>]
126
127
  # @api public
127
128
  def provider_files
128
- @provider_files ||= provider_paths.each_with_object([[], []]) { |path, (provider_files, loaded)| # rubocop:disable Layout/LineLength
129
+ @provider_files ||= provider_paths.each_with_object([[], []]) { |path, (provider_files, loaded)|
129
130
  files = ::Dir["#{path}/#{RB_GLOB}"]
130
131
 
131
132
  files.each do |file|
@@ -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
@@ -42,8 +44,8 @@ module Dry
42
44
  else
43
45
  settings_obj.config[setting.name]
44
46
  end
45
- rescue => e # rubocop:disable Style/RescueStandardError
46
- errors[setting.name] = e
47
+ rescue => exception # rubocop:disable Style/RescueStandardError
48
+ errors[setting.name] = exception
47
49
  end
48
50
  end
49
51
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module System
5
- VERSION = "1.2.4"
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.4
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - Piotr Solnica
8
- autorequire:
9
- bindir: bin
7
+ - Hanakai team
8
+ bindir: exe
10
9
  cert_chain: []
11
- date: 2025-08-14 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
@@ -66,12 +65,57 @@ dependencies:
66
65
  - - "~>"
67
66
  - !ruby/object:Gem::Version
68
67
  version: '1.1'
68
+ - !ruby/object:Gem::Dependency
69
+ name: bundler
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ - !ruby/object:Gem::Dependency
83
+ name: rake
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ - !ruby/object:Gem::Dependency
97
+ name: rspec
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
69
110
  description: Organize your code into reusable components
70
111
  email:
71
- - piotr.solnica@gmail.com
112
+ - info@hanakai.org
72
113
  executables: []
73
114
  extensions: []
74
- extra_rdoc_files: []
115
+ extra_rdoc_files:
116
+ - CHANGELOG.md
117
+ - LICENSE
118
+ - README.md
75
119
  files:
76
120
  - CHANGELOG.md
77
121
  - LICENSE
@@ -123,12 +167,10 @@ homepage: https://dry-rb.org/gems/dry-system
123
167
  licenses:
124
168
  - MIT
125
169
  metadata:
126
- allowed_push_host: https://rubygems.org
127
170
  changelog_uri: https://github.com/dry-rb/dry-system/blob/main/CHANGELOG.md
128
171
  source_code_uri: https://github.com/dry-rb/dry-system
129
172
  bug_tracker_uri: https://github.com/dry-rb/dry-system/issues
130
- rubygems_mfa_required: 'true'
131
- post_install_message:
173
+ funding_uri: https://github.com/sponsors/hanami
132
174
  rdoc_options: []
133
175
  require_paths:
134
176
  - lib
@@ -136,15 +178,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
178
  requirements:
137
179
  - - ">="
138
180
  - !ruby/object:Gem::Version
139
- version: '3.1'
181
+ version: '3.3'
140
182
  required_rubygems_version: !ruby/object:Gem::Requirement
141
183
  requirements:
142
184
  - - ">="
143
185
  - !ruby/object:Gem::Version
144
186
  version: '0'
145
187
  requirements: []
146
- rubygems_version: 3.3.27
147
- signing_key:
188
+ rubygems_version: 3.6.9
148
189
  specification_version: 4
149
190
  summary: Organize your code into reusable components
150
191
  test_files: []