dry-system 0.22.0 → 0.25.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +424 -0
- data/LICENSE +1 -1
- data/README.md +3 -3
- data/dry-system.gemspec +4 -5
- data/lib/dry/system/component.rb +10 -5
- data/lib/dry/system/component_dir.rb +14 -35
- data/lib/dry/system/components.rb +8 -4
- data/lib/dry/system/config/component_dir.rb +60 -16
- data/lib/dry/system/config/component_dirs.rb +23 -10
- data/lib/dry/system/config/namespace.rb +4 -6
- data/lib/dry/system/constants.rb +1 -1
- data/lib/dry/system/container.rb +275 -192
- data/lib/dry/system/errors.rb +73 -53
- data/lib/dry/system/identifier.rb +62 -20
- data/lib/dry/system/importer.rb +90 -12
- data/lib/dry/system/indirect_component.rb +1 -1
- data/lib/dry/system/loader.rb +6 -1
- data/lib/dry/system/{manual_registrar.rb → manifest_registrar.rb} +9 -6
- data/lib/dry/system/plugins/bootsnap.rb +2 -1
- data/lib/dry/system/plugins/dependency_graph/strategies.rb +37 -1
- data/lib/dry/system/plugins/dependency_graph.rb +26 -20
- data/lib/dry/system/plugins/env.rb +2 -1
- data/lib/dry/system/plugins/logging.rb +2 -2
- data/lib/dry/system/plugins/monitoring.rb +1 -1
- data/lib/dry/system/plugins/notifications.rb +1 -1
- data/lib/dry/system/plugins/zeitwerk/compat_inflector.rb +22 -0
- data/lib/dry/system/plugins/zeitwerk.rb +109 -0
- data/lib/dry/system/plugins.rb +7 -4
- data/lib/dry/system/provider/source.rb +329 -0
- data/lib/dry/system/provider/source_dsl.rb +94 -0
- data/lib/dry/system/provider.rb +262 -22
- data/lib/dry/system/provider_registrar.rb +276 -0
- data/lib/dry/system/provider_source_registry.rb +70 -0
- data/lib/dry/system/provider_sources/settings/config.rb +86 -0
- data/lib/dry/system/provider_sources/settings/loader.rb +53 -0
- data/lib/dry/system/provider_sources/settings.rb +40 -0
- data/lib/dry/system/provider_sources.rb +5 -0
- data/lib/dry/system/version.rb +1 -1
- data/lib/dry/system.rb +44 -12
- metadata +23 -37
- data/lib/dry/system/booter/component_registry.rb +0 -35
- data/lib/dry/system/booter.rb +0 -200
- data/lib/dry/system/components/bootable.rb +0 -280
- data/lib/dry/system/components/config.rb +0 -35
- data/lib/dry/system/lifecycle.rb +0 -135
- data/lib/dry/system/provider_registry.rb +0 -27
- data/lib/dry/system/settings/file_loader.rb +0 -30
- data/lib/dry/system/settings/file_parser.rb +0 -51
- data/lib/dry/system/settings.rb +0 -64
- data/lib/dry/system/system_components/settings.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ee8640692f53a8c0a9a29fd59bfe5595a269b3680d4a8f71d630e87ed2398b9
|
4
|
+
data.tar.gz: 435806646f338c4bdec369ae98fc29f451bb6a5dbe38bc2f20d7c3cb422b4223
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90130f6f367b24a1b45fd6be2915efe9d0c9e22b676e03b3a827ea7e9d02accca210272c8f5cd330993f2ea378ca2674ffc9281f7d695b14b7acb6f4d0a24c6d
|
7
|
+
data.tar.gz: 30cb6a24cb9e12cbd259223d0b861f837b692e139b21f95e1dfdd6b0365129e37377153151bce0cda8b9171249507ff458e4239ac61df0200c7144063381c0ad
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,429 @@
|
|
1
1
|
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
2
|
|
3
|
+
## 0.25.0 2022-07-10
|
4
|
+
|
5
|
+
|
6
|
+
### Fixed
|
7
|
+
|
8
|
+
- Fix incorrect type in `ManifestRegistrar#finalize!` (@alassek)
|
9
|
+
|
10
|
+
### Changed
|
11
|
+
|
12
|
+
- Import root components via `nil` import namespace (via #236) (@timriley)
|
13
|
+
- Allow deeper `Provider::Source` hierarchies (via #240) (@timriley + @solnic)
|
14
|
+
- Prefer local components when importing (via #241) (@timriley + @solnic)
|
15
|
+
|
16
|
+
[Compare v0.24.0...v0.25.0](https://github.com/dry-rb/dry-system/compare/v0.24.0...v0.25.0)
|
17
|
+
|
18
|
+
## 0.24.0
|
19
|
+
|
20
|
+
|
21
|
+
### Changed
|
22
|
+
|
23
|
+
- dry-struct depedency was removed (@flash-gordon)
|
24
|
+
|
25
|
+
[Compare v0.23.0...master](https://github.com/dry-rb/dry-system/compare/v0.23.0...master)
|
26
|
+
|
27
|
+
## 0.23.0 2022-02-08
|
28
|
+
|
29
|
+
This is a major overhaul of bootable components (now known as “Providers”), and brings major advancements to other areas, including container imports and exports.
|
30
|
+
|
31
|
+
Deprecations are in place for otherwise breaking changes to commonly used parts of dry-system, though some breaking changes remain.
|
32
|
+
|
33
|
+
This prepares the way for dry-system 1.0, which will be released in the coming months.
|
34
|
+
|
35
|
+
|
36
|
+
### Added
|
37
|
+
|
38
|
+
- Containers can configure specific components for export using `config.exports` (@timriley in #209).
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
class MyContainer < Dry::System::Container
|
42
|
+
configure do |config|
|
43
|
+
config.exports = %w[component_a component_b]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
Containers importing another container with configured exports will import only those components.
|
49
|
+
|
50
|
+
When importing a specific set of components (see the note in the “Changed” section below), only those components whose keys intersect with the configured exports will be imported.
|
51
|
+
- A `:zeitwerk` plugin, to set up [Zeitwerk](https://github.com/fxn/zeitwerk) and integrate it with your container configuration (@ianks and @timriley in #197, #222, 13f8c87, #223)
|
52
|
+
|
53
|
+
This makes it possible to enable Zeitwerk with a one-liner:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
class MyContainer < Dry::System::Container
|
57
|
+
use :zeitwerk
|
58
|
+
|
59
|
+
configure do |config|
|
60
|
+
config.component_dirs.add "lib"
|
61
|
+
# ...
|
62
|
+
end
|
63
|
+
end
|
64
|
+
```
|
65
|
+
|
66
|
+
The plugin makes a `Zeitwerk::Loader` instance available at `config.autoloader`, and then in an after-`:configure` hook, the plugin will set up the loader to work with all of your configured component dirs and their namespaces. It will also enable the `Dry::System::Loader::Autoloading` loader for all component dirs, plus disable those dirs from being added to the `$LOAD_PATH`.
|
67
|
+
|
68
|
+
The plugin accepts the following options:
|
69
|
+
|
70
|
+
- `loader:` - (optional) to use a pre-initialized loader, if required.
|
71
|
+
- `run_setup:` - (optional) a bool to determine whether to run `Zeitwerk::Loader#setup` as part of the after-`:configure` hook. This may be useful to disable in advanced cases when integrating with an externally managed loader.
|
72
|
+
- `eager_load:` - (optional) a bool to determine whether to run `Zeitwerk::Loader#eager_load` as part of an after-`:finalize` hook. When not provided, it will default to true if the `:env` plugin is enabled and the env is set to `:production`.
|
73
|
+
- `debug:` - (optional) a bool to set whether Zeitwerk should log to `$stdout`.
|
74
|
+
- New `Identifier#end_with?` and `Identifier#include?` predicates (@timriley in #219)
|
75
|
+
|
76
|
+
These are key segment-aware predicates that can be useful when checking components as part of container configuration.
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
identifier.key # => "articles.operations.create"
|
80
|
+
|
81
|
+
identifier.end_with?("create") # => true
|
82
|
+
identifier.end_with?("operations.create") # => true
|
83
|
+
identifier.end_with?("ate") # => false, not a whole segment
|
84
|
+
identifier.end_with?("nope") # => false, not part of the key at all
|
85
|
+
|
86
|
+
identifier.include?("operations") # => true
|
87
|
+
identifier.include?("articles.operations") # => true
|
88
|
+
identifier.include?("operations.create") # => true
|
89
|
+
identifier.include?("article") # false, not a whole segment
|
90
|
+
identifier.include?("update") # => false, not part of the key at all
|
91
|
+
```
|
92
|
+
- An `instance` setting for component dirs allows simpler per-dir control over component instantiation (@timriley in #215)
|
93
|
+
|
94
|
+
This optional setting should be provided a proc that receives a single `Dry::System::Component` instance as an argument, and should return the instance for the given component.
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
configure do |config|
|
98
|
+
config.component_dirs.add "lib" do |dir|
|
99
|
+
dir.instance = proc do |component|
|
100
|
+
if component.identifier.include?("workers")
|
101
|
+
# Register classes for jobs
|
102
|
+
component.loader.constant(component)
|
103
|
+
else
|
104
|
+
# Otherwise register regular instances per default loader
|
105
|
+
component.loader.call(component)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
```
|
111
|
+
|
112
|
+
For complete control of component loading, you should continue to configure the component dir’s `loader` instead.
|
113
|
+
- A new `ComponentNotLoadableError` error and helpful message is raised when resolving a component and an unexpected class is defined in the component’s source file (@cllns in #217).
|
114
|
+
|
115
|
+
The error shows expected and found class names, and inflector configuration that may be required in the case of class names containing acronyms.
|
116
|
+
|
117
|
+
### Fixed
|
118
|
+
|
119
|
+
- Registrations made in providers (by calling `register` inside a provider step) have all their registration options preserved (such as a block-based registration, or the `memoize:` option) when having their registration merged into the target container after the provider lifecycle steps complete (@timriley in #212).
|
120
|
+
- Providers can no longer implicitly re-start themselves while in the process of starting and cause an infinite loop (@timriley #213).
|
121
|
+
|
122
|
+
This was possible before when a provider resolved a component from the target container that auto-injected dependencies with container keys sharing the same base key as the provider name.
|
123
|
+
|
124
|
+
### Changed
|
125
|
+
|
126
|
+
- “Bootable components” (also referred to in some places simply as “components”) have been renamed to “Providers” (@timriley in #200).
|
127
|
+
|
128
|
+
Register a provider with `Dry::System::Container.register_provider` (`Dry::System::Container.boot` has been deprecated):
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
MyContainer.register_provider(:mailer) do
|
132
|
+
# ...
|
133
|
+
end
|
134
|
+
```
|
135
|
+
- Provider `init` lifecycle step has been deprecated and renamed to `prepare` (@timriley in #200).
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
MyContainer.reigster_provider(:mailer) do
|
139
|
+
# Rename `init` to `prepare`
|
140
|
+
prepare do
|
141
|
+
require "some/third_party/mailer"
|
142
|
+
end
|
143
|
+
end
|
144
|
+
```
|
145
|
+
- Provider behavior is now backed by a class per provider, known as the “Provider source” (@timriley in #202).
|
146
|
+
|
147
|
+
The provider source class is created for each provider as a subclass of `Dry::System::Provider::Source`.
|
148
|
+
|
149
|
+
You can still register simple providers using the block-based DSL, but the class backing means you can share state between provider steps using regular instance variables:
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
MyContainer.reigster_provider(:mailer) do
|
153
|
+
prepare do
|
154
|
+
require "some/third_party/mailer"
|
155
|
+
@some_config = ThirdParty::Mailer::Config.new
|
156
|
+
end
|
157
|
+
|
158
|
+
start do
|
159
|
+
# Since the `prepare` step will always run before start, we can access
|
160
|
+
# @some_config here
|
161
|
+
register "mailer", ThirdParty::Mailer.new(@some_config)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
```
|
165
|
+
|
166
|
+
Inside this `register_provider` block, `self` is the source subclass itself, and inside each of the step blocks (i.e. `prepare do`), `self` will be the _instance_ of that provider source.
|
167
|
+
|
168
|
+
For more complex providers, you can define your own source subclass and register it directly with the `source:` option for `register_provider`. This allows you to more readily use standard arrangements for factoring your logic within a class, such as extraction to another method:
|
169
|
+
|
170
|
+
```ruby
|
171
|
+
MyContainer.register_provider(:mailer, source: Class.new(Dry::System::Provider::Source) {
|
172
|
+
# The provider lifecycle steps are ordinary methods
|
173
|
+
def prepare
|
174
|
+
end
|
175
|
+
|
176
|
+
def start
|
177
|
+
mailer = some_complex_logic_to_build_the_mailer(some: "config")
|
178
|
+
register(:mailer, mailer)
|
179
|
+
end
|
180
|
+
|
181
|
+
private
|
182
|
+
|
183
|
+
def some_complex_logic_to_build_the_mailer(**options)
|
184
|
+
# ...
|
185
|
+
end
|
186
|
+
})
|
187
|
+
```
|
188
|
+
- The block argument to `Dry::System::Container.register_provider` (previously `.boot`) has been deprecated. (@timriley in #202).
|
189
|
+
|
190
|
+
This argument was used to give you access to the provider's target container (i.e. the container on which you were registering the provider).
|
191
|
+
|
192
|
+
To access the target container, you can use `#target_container` (or `#target` as a convenience alias) instead.
|
193
|
+
|
194
|
+
You can also access the provider's own container (which is where the provider's components are registered when you call `register` directly inside a provider step) as `#provider_container` (or `#container` as a convenience alias).
|
195
|
+
- `use(provider_name)` inside a provider step has been deprecated. Use `target_container.start(provider_name)` instead (@timriley in #211 and #224)
|
196
|
+
|
197
|
+
Now that you can access `target_container` consistently within all provider steps, you can use it to also start any other providers as you require without any special additional method. This also allows you to invoke other provider lifecycle steps, like `target_container.prepare(provider_name)`.
|
198
|
+
- `method_missing`-based delegation within providers to target container registrations has been removed (**BREAKING**) (@timriley in #202)
|
199
|
+
|
200
|
+
Delegation to registrations with the provider's own container has been kept, since it can be a convenient way to access registrations made in a prior lifecycle step:
|
201
|
+
|
202
|
+
```ruby
|
203
|
+
MyContainer.register_provider(:mailer, namespace: true) do
|
204
|
+
prepare do
|
205
|
+
register :config, "mailer config here"
|
206
|
+
end
|
207
|
+
|
208
|
+
start do
|
209
|
+
config # => "mailer config here"
|
210
|
+
end
|
211
|
+
end
|
212
|
+
```
|
213
|
+
- The previous "external component" and "provider" concepts have been renamed to "external provider sources", in keeping with the new provider terminology outlined above (@timriley in #200 and #202).
|
214
|
+
|
215
|
+
You can register a collection of external provider sources defined in their own source files via `Dry::System.register_provider_sources` (`Dry::System.register_provider` has been deprecated):
|
216
|
+
|
217
|
+
```ruby
|
218
|
+
require "dry/system"
|
219
|
+
|
220
|
+
Dry::System.register_provider_sources(path)
|
221
|
+
```
|
222
|
+
|
223
|
+
You can register an individual external provider source via `Dry::System.register_provider_source` (`Dry::System.register_component` has been deprecated):
|
224
|
+
|
225
|
+
```ruby
|
226
|
+
Dry::System.register_provider_source(:something, group: :my_gem) do
|
227
|
+
start do
|
228
|
+
# ...
|
229
|
+
end
|
230
|
+
end
|
231
|
+
```
|
232
|
+
|
233
|
+
Just like providers, you can also register a class as an external provider source:
|
234
|
+
|
235
|
+
```ruby
|
236
|
+
module MyGem
|
237
|
+
class MySource < Dry::System::Provider::Source
|
238
|
+
def start
|
239
|
+
# ...
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
Dry::System.register_provider_source(:something, group: :my_gem, source: MyGem::MySource)
|
245
|
+
```
|
246
|
+
|
247
|
+
The `group:` argument when registering an external provider sources is for preventing name clashes between provider sources. You should use an underscored version of your gem name or namespace when registering your own provider sources.
|
248
|
+
- Registering a provider using an explicitly named external provider source via `key:` argument is deprecated, use the `source:` argument instead (@timriley in #202).
|
249
|
+
|
250
|
+
You can register a provider using the same name as an external provider source by specifying the `from:` argument only, as before:
|
251
|
+
|
252
|
+
```ruby
|
253
|
+
# Elsewhere
|
254
|
+
Dry::System.register_provider_source(:something, group: :my_gem) { ... }
|
255
|
+
|
256
|
+
# In your app:
|
257
|
+
MyContainer.register_provider(:something, from: :my_gem)
|
258
|
+
```
|
259
|
+
|
260
|
+
When you wish the name your provider differently, this is when you need to use the `source:` argument:
|
261
|
+
|
262
|
+
```ruby
|
263
|
+
MyContainer.register_provider(:differently_named, from: :my_gem, source: :something)
|
264
|
+
```
|
265
|
+
|
266
|
+
When you're registering a provider using an external provider source, you cannot provie your own `Dry::System::Provider::Source` subclass as the `source:`, since that source class is being provided by the external provider source.
|
267
|
+
- Provider source settings are now defined using dry-configurable’s `setting` API at the top-level scope (@timriley in #202).
|
268
|
+
|
269
|
+
Use the top-level `setting` method to define your settings (the `settings` block and settings defined inside the block using `key` is deprecated). Inside the provider steps, the configured settings can be accessed as `config`:
|
270
|
+
|
271
|
+
```ruby
|
272
|
+
# In the external provider source
|
273
|
+
Dry::System.register_provider_source(:something, group: :my_gem) do
|
274
|
+
setting :my_option
|
275
|
+
|
276
|
+
start do
|
277
|
+
# Do something with `config.my_option` here
|
278
|
+
end
|
279
|
+
end
|
280
|
+
```
|
281
|
+
|
282
|
+
When using an external provider source, configure the source via the `#configure`:
|
283
|
+
|
284
|
+
```ruby
|
285
|
+
# In your application's provider using the external source
|
286
|
+
MyContainer.register_provider(:something, from: :my_gem) do
|
287
|
+
configure do |config|
|
288
|
+
config.my_option = "some value"
|
289
|
+
end
|
290
|
+
end
|
291
|
+
```
|
292
|
+
|
293
|
+
To provide default values and type checking or constraints for your settings, use the dry-configurable’s `default:` and `constructor:` arguments:
|
294
|
+
|
295
|
+
```ruby
|
296
|
+
# Constructor can take any proc being passed the provided value
|
297
|
+
setting :my_option, default: "hello", constructor: -> (v) { v.to_s.upcase }
|
298
|
+
|
299
|
+
# Constructor will also work with dry-types objects
|
300
|
+
setting :my_option, default: "hello", constructor: Types::String.constrained(min_size: 3)
|
301
|
+
```
|
302
|
+
- External provider sources can define their own methods for use by the providers alongside lifecycle steps (@timriley in #202).
|
303
|
+
|
304
|
+
Now that provider sources are class-backed, external provider sources can define their own methods to be made available when that provider source is used. This makes it possible to define your own extended API for interacting with the provider source:
|
305
|
+
|
306
|
+
```ruby
|
307
|
+
# In the external provider source
|
308
|
+
|
309
|
+
module MyGem
|
310
|
+
class MySource < Dry::System::Provider::Source
|
311
|
+
# Standard lifecycle steps
|
312
|
+
def start
|
313
|
+
# Do something with @on_start here
|
314
|
+
end
|
315
|
+
|
316
|
+
# Custom behavior available when this provider source is used in a provider
|
317
|
+
def on_start(&block)
|
318
|
+
@on_start = block
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
Dry::System.register_provider_source(:something, group: :my_gem, source: MyGem::MySource)
|
324
|
+
|
325
|
+
# In your application's provider using the external source
|
326
|
+
|
327
|
+
MyContainer.register_provider(:something, from: :my_gem) do
|
328
|
+
# Use the custom method!
|
329
|
+
on_start do
|
330
|
+
# ...
|
331
|
+
end
|
332
|
+
end
|
333
|
+
```
|
334
|
+
- Providers can be registered conditionally using the `if:` option (@timriley in #218).
|
335
|
+
|
336
|
+
You should provide a simple truthy or falsey value to `if:`, and in the case of falsey value, the provider will not be registered.
|
337
|
+
|
338
|
+
This is useful in cases where you have providers that are loaded explicitly for specific runtime configurations of your app (e.g. when they are needed for specific tasks or processes only), but you do not need them for your primaary app process, for which you may finalize your container.
|
339
|
+
- `bootable_dirs` container setting has been deprecated and replaced by `provider_dirs` (@timriley in #200).
|
340
|
+
|
341
|
+
The default value for `provider_dirs` is now `"system/providers`".
|
342
|
+
- Removed the unused `system_dir` container setting (**BREAKING**) (@timriley in #200)
|
343
|
+
|
344
|
+
If you’ve configured this inside your container, you can remove it.
|
345
|
+
- dry-system’s first-party external provider sources now available via `require "dry/system/provider_sources"`, with the previous `require "dry/system/components"` deprecated (@timriley in #202).
|
346
|
+
- When using registering a provider using a first-party dry-system provider source, `from: :dry_system` instead of `from: :system` (which is now deprecated) (@timriley in #202).
|
347
|
+
|
348
|
+
```ruby
|
349
|
+
MyContainer.register_provider(:settings, from: :dry_system) do
|
350
|
+
# ...
|
351
|
+
end
|
352
|
+
- When registering a provider using the `:settings` provider source, settings are now defined using `setting` inside a `settings` block, rather than `key`, which is deprecated (@timriley in #202).
|
353
|
+
|
354
|
+
This `setting` method uses the dry-configurable setting API:
|
355
|
+
|
356
|
+
```ruby
|
357
|
+
MyContainer.register_provider(:settings, from: :dry_system) do
|
358
|
+
settings do
|
359
|
+
# Previously:
|
360
|
+
# key :my_int_setting, MyTypes::Coercible::Integer
|
361
|
+
|
362
|
+
# Now:
|
363
|
+
setting :my_setting, default: 0, constructor: MyTypes::Coercible::Integer
|
364
|
+
end
|
365
|
+
end
|
366
|
+
```
|
367
|
+
- The `:settings` provider source now requires the dotenv gem to load settings from `.env*` files (**BREAKING**) (@timriley in #204)
|
368
|
+
|
369
|
+
To ensure you can load your settings from these `.env*` files, add `gem "dotenv"` to your `Gemfile`.
|
370
|
+
- `Dry::System::Container` can be now be configured direclty using the setting writer methods on the class-level `.config` object, without going the `.configure(&block)` API (@timriley in #207).
|
371
|
+
|
372
|
+
If configuring via the class-level `.config` object, you should call `.configured!` after you're completed your configuration, which will finalize (freeze) the `config` object and then run any after-`:configure` hooks.
|
373
|
+
- `Dry::System::Container.configure(&block)` will now finalize (freeze) the `config` object by default, before returning (@timriley in #207).
|
374
|
+
|
375
|
+
You can opt out of this behavior by passing the `finalize_config: false` option:
|
376
|
+
|
377
|
+
```ruby
|
378
|
+
class MyContainer < Dry::System::Container
|
379
|
+
configure(finalize_config: false) do |config|
|
380
|
+
# ...
|
381
|
+
end
|
382
|
+
|
383
|
+
# `config` is still non-finalized here
|
384
|
+
end
|
385
|
+
```
|
386
|
+
- `Dry::System::Container.finalize!` will call `.configured!` (if it has not yet been called) before doing its work (@timriley in #207)
|
387
|
+
|
388
|
+
This ensures config finalization is an intrinsic part of the overall container finalization process.
|
389
|
+
- The `Dry::System::Container` `before(:configure)` hook has been removed (**BREAKING**) (@timriley in #207).
|
390
|
+
|
391
|
+
This was previously used for plugins to register their own settings, but this was not necessary given that plugins are modules, and can use their ordinary `.extended(container_class)` hook to register their settings. Essentially, any time after container subclass definition is "before configure" in nature.
|
392
|
+
- Container plugins should define their settings on the container using their module `.extended` hook, no longer in a `before(:configure)` hook (as above) (**BREAKING**) (@timriley in #207).
|
393
|
+
|
394
|
+
This ensures the plugin settings are available immediately after you’ve enabled the plugin via `Dry::System::Container.use`.
|
395
|
+
- The `Dry::System::Container` key `namespace_separator` setting is no longer expected to be user-configured. A key namespace separator of "." is hard-coded and expected to remain the separator string. (@timriley in #206)
|
396
|
+
- Containers can import a specific subset of another container’s components via changes to `.import`, which is now `.import(keys: nil, from:, as:)` (with prior API deprecated) (@timriley in #209)
|
397
|
+
|
398
|
+
To import specific components:
|
399
|
+
|
400
|
+
```ruby
|
401
|
+
class MyContainer < Dry::System::Container
|
402
|
+
# config, etc.
|
403
|
+
|
404
|
+
# Will import components with keys "other.component_a", "other.component_b"
|
405
|
+
import(
|
406
|
+
keys: %w[component_a component_b],
|
407
|
+
from: OtherContainer,
|
408
|
+
as: :other
|
409
|
+
)
|
410
|
+
```
|
411
|
+
|
412
|
+
Omitting `keys:` will import all the components available from the other container.
|
413
|
+
- Components imported into a container from another will be protected from subsequent export unless explicitly configured in `config.exports` (@timriley in #209)
|
414
|
+
|
415
|
+
Imported components are considered “private” by default because they did not originate in container that imported them.
|
416
|
+
|
417
|
+
This ensures there are no redundant imports in arrangements where multiple all containers import a common “base” container, and then some of those containers then import each other.
|
418
|
+
- Container imports are now made without finalizing the exporting container in most cases, ensuring more efficient imports (@timriley in #209)
|
419
|
+
|
420
|
+
Now, the only time the exporting container will be finalized is when a container is importing all components, and the exporting container has not declared any components in `config.exports`.
|
421
|
+
- [Internal] The `manual_registrar` container setting and associated `ManualRegistrar` class have been renamed to `manifest_registrar` and `ManifestRegistrar` respectively (**BREAKING**) (@timriley in #208).
|
422
|
+
- The default value for the container `registrations_dir` setting has been changed from `"container"` to `"system/registrations"` (**BREAKING**) (@timriley in #208)
|
423
|
+
- The `:dependency_graph` plugin now supports all dry-auto_inject injector strategies (@davydovanton and @timriley in #214)
|
424
|
+
|
425
|
+
[Compare v0.22.0...v0.23.0](https://github.com/dry-rb/dry-system/compare/v0.22.0...v0.23.0)
|
426
|
+
|
3
427
|
## 0.22.0 2022-01-06
|
4
428
|
|
5
429
|
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
[![CI Status](https://github.com/dry-rb/dry-system/workflows/ci/badge.svg)][actions]
|
12
12
|
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/3a0e30d0ae2542c7ba047ba5f923c0bb)][codacy]
|
13
13
|
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/3a0e30d0ae2542c7ba047ba5f923c0bb)][codacy]
|
14
|
-
[![Inline docs](http://inch-ci.org/github/dry-rb/dry-system.svg?branch=
|
14
|
+
[![Inline docs](http://inch-ci.org/github/dry-rb/dry-system.svg?branch=main)][inchpages]
|
15
15
|
|
16
16
|
## Links
|
17
17
|
|
@@ -22,8 +22,8 @@
|
|
22
22
|
|
23
23
|
This library officially supports the following Ruby versions:
|
24
24
|
|
25
|
-
* MRI `>= 2.
|
26
|
-
* jruby `>= 9.3`
|
25
|
+
* MRI `>= 2.7.0`
|
26
|
+
* jruby `>= 9.3` (postponed until 2.7 is supported)
|
27
27
|
|
28
28
|
## License
|
29
29
|
|
data/dry-system.gemspec
CHANGED
@@ -22,20 +22,19 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
24
|
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
25
|
-
spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-system/blob/
|
25
|
+
spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-system/blob/main/CHANGELOG.md"
|
26
26
|
spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-system"
|
27
27
|
spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-system/issues"
|
28
28
|
|
29
|
-
spec.required_ruby_version = ">= 2.
|
29
|
+
spec.required_ruby_version = ">= 2.7.0"
|
30
30
|
|
31
31
|
# to update dependencies edit project.yml
|
32
32
|
spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
|
33
33
|
spec.add_runtime_dependency "dry-auto_inject", ">= 0.4.0"
|
34
|
-
spec.add_runtime_dependency "dry-configurable", "~> 0.
|
35
|
-
spec.add_runtime_dependency "dry-container", "~> 0.
|
34
|
+
spec.add_runtime_dependency "dry-configurable", "~> 0.14", ">= 0.14.0"
|
35
|
+
spec.add_runtime_dependency "dry-container", "~> 0.10", ">= 0.10.0"
|
36
36
|
spec.add_runtime_dependency "dry-core", "~> 0.5", ">= 0.5"
|
37
37
|
spec.add_runtime_dependency "dry-inflector", "~> 0.1", ">= 0.1.2"
|
38
|
-
spec.add_runtime_dependency "dry-struct", "~> 1.0"
|
39
38
|
|
40
39
|
spec.add_development_dependency "bundler"
|
41
40
|
spec.add_development_dependency "rake"
|
data/lib/dry/system/component.rb
CHANGED
@@ -7,6 +7,7 @@ require "dry/inflector"
|
|
7
7
|
require "dry/system/loader"
|
8
8
|
require "dry/system/errors"
|
9
9
|
require "dry/system/constants"
|
10
|
+
require "pathname"
|
10
11
|
require_relative "identifier"
|
11
12
|
|
12
13
|
module Dry
|
@@ -17,10 +18,9 @@ module Dry
|
|
17
18
|
#
|
18
19
|
# @api public
|
19
20
|
class Component
|
20
|
-
include Dry::Equalizer(:identifier, :namespace, :options)
|
21
|
+
include Dry::Equalizer(:identifier, :file_path, :namespace, :options)
|
21
22
|
|
22
23
|
DEFAULT_OPTIONS = {
|
23
|
-
separator: DEFAULT_SEPARATOR,
|
24
24
|
inflector: Dry::Inflector.new,
|
25
25
|
loader: Loader
|
26
26
|
}.freeze
|
@@ -29,6 +29,10 @@ module Dry
|
|
29
29
|
# @return [String] the component's unique identifier
|
30
30
|
attr_reader :identifier
|
31
31
|
|
32
|
+
# @!attribute [r] file_path
|
33
|
+
# @return [Pathname] the component's source file path
|
34
|
+
attr_reader :file_path
|
35
|
+
|
32
36
|
# @!attribute [r] namespace
|
33
37
|
# @return [Dry::System::Config::Namespace] the component's namespace
|
34
38
|
attr_reader :namespace
|
@@ -38,8 +42,9 @@ module Dry
|
|
38
42
|
attr_reader :options
|
39
43
|
|
40
44
|
# @api private
|
41
|
-
def initialize(identifier, namespace:, **options)
|
45
|
+
def initialize(identifier, file_path:, namespace:, **options)
|
42
46
|
@identifier = identifier
|
47
|
+
@file_path = Pathname(file_path)
|
43
48
|
@namespace = namespace
|
44
49
|
@options = DEFAULT_OPTIONS.merge(options)
|
45
50
|
end
|
@@ -61,7 +66,7 @@ module Dry
|
|
61
66
|
# @return [Object] component's class instance
|
62
67
|
# @api public
|
63
68
|
def instance(*args)
|
64
|
-
loader.call(self, *args)
|
69
|
+
options[:instance]&.call(self, *args) || loader.call(self, *args)
|
65
70
|
end
|
66
71
|
ruby2_keywords(:instance) if respond_to?(:ruby2_keywords, true)
|
67
72
|
|
@@ -137,7 +142,7 @@ module Dry
|
|
137
142
|
#
|
138
143
|
# @api public
|
139
144
|
def const_path
|
140
|
-
namespace_const_path = namespace.const&.gsub(
|
145
|
+
namespace_const_path = namespace.const&.gsub(KEY_SEPARATOR, PATH_SEPARATOR)
|
141
146
|
|
142
147
|
if namespace_const_path
|
143
148
|
"#{namespace_const_path}#{PATH_SEPARATOR}#{path_in_namespace}"
|
@@ -42,8 +42,8 @@ module Dry
|
|
42
42
|
#
|
43
43
|
# @api private
|
44
44
|
def component_for_key(key)
|
45
|
-
namespaces.each do |namespace|
|
46
|
-
identifier = Identifier.new(key
|
45
|
+
config.namespaces.each do |namespace|
|
46
|
+
identifier = Identifier.new(key)
|
47
47
|
|
48
48
|
next unless identifier.start_with?(namespace.key)
|
49
49
|
|
@@ -65,37 +65,12 @@ module Dry
|
|
65
65
|
|
66
66
|
private
|
67
67
|
|
68
|
-
def namespaces
|
69
|
-
config.namespaces.to_a.map { |namespace| normalize_namespace(namespace) }
|
70
|
-
end
|
71
|
-
|
72
|
-
# Returns an array of "normalized" namespaces, safe for loading components
|
73
|
-
#
|
74
|
-
# This works around the issue of a namespace being added for a nested path but
|
75
|
-
# _without_ specifying a key namespace. In this case, the key namespace will defaut
|
76
|
-
# to match the path, meaning it will contain path separators instead of the
|
77
|
-
# container's configured `namespace_separator` (due to `Config::Namespaces` not
|
78
|
-
# being able to know the configured `namespace_separator`), so we need to replace
|
79
|
-
# the path separators with the proper `namespace_separator` here (where we _do_ know
|
80
|
-
# what it is).
|
81
|
-
def normalize_namespace(namespace)
|
82
|
-
if namespace.path&.include?(PATH_SEPARATOR) && namespace.default_key?
|
83
|
-
namespace = namespace.class.new(
|
84
|
-
path: namespace.path,
|
85
|
-
key: namespace.key.gsub(PATH_SEPARATOR, container.config.namespace_separator),
|
86
|
-
const: namespace.const
|
87
|
-
)
|
88
|
-
end
|
89
|
-
|
90
|
-
namespace
|
91
|
-
end
|
92
|
-
|
93
68
|
def each_file
|
94
69
|
return enum_for(:each_file) unless block_given?
|
95
70
|
|
96
71
|
raise ComponentDirNotFoundError, full_path unless Dir.exist?(full_path)
|
97
72
|
|
98
|
-
namespaces.each do |namespace|
|
73
|
+
config.namespaces.each do |namespace|
|
99
74
|
files(namespace).each do |file|
|
100
75
|
yield file, namespace
|
101
76
|
end
|
@@ -106,7 +81,7 @@ module Dry
|
|
106
81
|
if namespace.path?
|
107
82
|
Dir[File.join(full_path, namespace.path, "**", RB_GLOB)].sort
|
108
83
|
else
|
109
|
-
non_root_paths = namespaces.to_a.reject(&:root?).map(&:path)
|
84
|
+
non_root_paths = config.namespaces.to_a.reject(&:root?).map(&:path)
|
110
85
|
|
111
86
|
Dir[File.join(full_path, "**", RB_GLOB)].reject { |file_path|
|
112
87
|
Pathname(file_path).relative_path_from(full_path).to_s.start_with?(*non_root_paths)
|
@@ -126,16 +101,14 @@ module Dry
|
|
126
101
|
# @param path [String] the full path to the file
|
127
102
|
# @return [Dry::System::Component] the component
|
128
103
|
def component_for_path(path, namespace)
|
129
|
-
separator = container.config.namespace_separator
|
130
|
-
|
131
104
|
key = Pathname(path).relative_path_from(full_path).to_s
|
132
105
|
.sub(RB_EXT, EMPTY_STRING)
|
133
106
|
.scan(WORD_REGEX)
|
134
|
-
.join(
|
107
|
+
.join(KEY_SEPARATOR)
|
135
108
|
|
136
|
-
identifier = Identifier.new(key
|
109
|
+
identifier = Identifier.new(key)
|
137
110
|
.namespaced(
|
138
|
-
from: namespace.path&.gsub(PATH_SEPARATOR,
|
111
|
+
from: namespace.path&.gsub(PATH_SEPARATOR, KEY_SEPARATOR),
|
139
112
|
to: namespace.key
|
140
113
|
)
|
141
114
|
|
@@ -168,13 +141,19 @@ module Dry
|
|
168
141
|
**MagicCommentsParser.(file_path)
|
169
142
|
}
|
170
143
|
|
171
|
-
Component.new(
|
144
|
+
Component.new(
|
145
|
+
identifier,
|
146
|
+
namespace: namespace,
|
147
|
+
file_path: file_path,
|
148
|
+
**options
|
149
|
+
)
|
172
150
|
end
|
173
151
|
|
174
152
|
def component_options
|
175
153
|
{
|
176
154
|
auto_register: auto_register,
|
177
155
|
loader: loader,
|
156
|
+
instance: instance,
|
178
157
|
memoize: memoize
|
179
158
|
}
|
180
159
|
end
|
@@ -1,8 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "dry/
|
3
|
+
require "dry/core/deprecations"
|
4
4
|
|
5
|
-
Dry::
|
6
|
-
|
7
|
-
|
5
|
+
Dry::Core::Deprecations.announce(
|
6
|
+
"require \"dry/system/components\"",
|
7
|
+
"Use `require \"dry/system/provider_sources\"` instead",
|
8
|
+
tag: "dry-system",
|
9
|
+
uplevel: 1
|
8
10
|
)
|
11
|
+
|
12
|
+
require_relative "provider_sources"
|