dry-system 0.18.1 → 1.0.1

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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +678 -0
  3. data/LICENSE +1 -1
  4. data/README.md +5 -4
  5. data/dry-system.gemspec +18 -21
  6. data/lib/dry/system/auto_registrar.rb +9 -64
  7. data/lib/dry/system/component.rb +124 -104
  8. data/lib/dry/system/component_dir.rb +171 -0
  9. data/lib/dry/system/config/component_dir.rb +228 -0
  10. data/lib/dry/system/config/component_dirs.rb +289 -0
  11. data/lib/dry/system/config/namespace.rb +75 -0
  12. data/lib/dry/system/config/namespaces.rb +196 -0
  13. data/lib/dry/system/constants.rb +2 -4
  14. data/lib/dry/system/container.rb +305 -345
  15. data/lib/dry/system/errors.rb +73 -56
  16. data/lib/dry/system/identifier.rb +176 -0
  17. data/lib/dry/system/importer.rb +89 -12
  18. data/lib/dry/system/indirect_component.rb +63 -0
  19. data/lib/dry/system/loader/autoloading.rb +24 -0
  20. data/lib/dry/system/loader.rb +49 -41
  21. data/lib/dry/system/{manual_registrar.rb → manifest_registrar.rb} +13 -14
  22. data/lib/dry/system/plugins/bootsnap.rb +3 -2
  23. data/lib/dry/system/plugins/dependency_graph/strategies.rb +38 -2
  24. data/lib/dry/system/plugins/dependency_graph.rb +25 -21
  25. data/lib/dry/system/plugins/env.rb +3 -2
  26. data/lib/dry/system/plugins/logging.rb +9 -8
  27. data/lib/dry/system/plugins/monitoring.rb +1 -2
  28. data/lib/dry/system/plugins/notifications.rb +1 -1
  29. data/lib/dry/system/plugins/plugin.rb +61 -0
  30. data/lib/dry/system/plugins/zeitwerk/compat_inflector.rb +22 -0
  31. data/lib/dry/system/plugins/zeitwerk.rb +109 -0
  32. data/lib/dry/system/plugins.rb +5 -73
  33. data/lib/dry/system/provider/source.rb +276 -0
  34. data/lib/dry/system/provider/source_dsl.rb +55 -0
  35. data/lib/dry/system/provider.rb +261 -23
  36. data/lib/dry/system/provider_registrar.rb +251 -0
  37. data/lib/dry/system/provider_source_registry.rb +56 -0
  38. data/lib/dry/system/provider_sources/settings/config.rb +73 -0
  39. data/lib/dry/system/provider_sources/settings/loader.rb +44 -0
  40. data/lib/dry/system/provider_sources/settings.rb +40 -0
  41. data/lib/dry/system/provider_sources.rb +5 -0
  42. data/lib/dry/system/stubs.rb +6 -2
  43. data/lib/dry/system/version.rb +1 -1
  44. data/lib/dry/system.rb +35 -13
  45. metadata +48 -97
  46. data/lib/dry/system/auto_registrar/configuration.rb +0 -43
  47. data/lib/dry/system/booter/component_registry.rb +0 -35
  48. data/lib/dry/system/booter.rb +0 -181
  49. data/lib/dry/system/components/bootable.rb +0 -289
  50. data/lib/dry/system/components/config.rb +0 -35
  51. data/lib/dry/system/components.rb +0 -8
  52. data/lib/dry/system/lifecycle.rb +0 -135
  53. data/lib/dry/system/provider_registry.rb +0 -27
  54. data/lib/dry/system/settings/file_loader.rb +0 -30
  55. data/lib/dry/system/settings/file_parser.rb +0 -51
  56. data/lib/dry/system/settings.rb +0 -67
  57. data/lib/dry/system/system_components/settings.rb +0 -11
data/CHANGELOG.md CHANGED
@@ -1,3 +1,681 @@
1
+ <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
+
3
+ ## 1.0.1 2022-11-18
4
+
5
+
6
+ ### Changed
7
+
8
+ - Bumped dry-auto_inject dependency to its 1.0.0 final release (@solnic)
9
+
10
+ [Compare v1.0.0...v1.0.1](https://github.com/dry-rb/dry-system/compare/v1.0.0...v1.0.1)
11
+
12
+ ## 1.0.0 2022-11-18
13
+
14
+
15
+ ### Fixed
16
+
17
+ - Only use DidYouMean-integrated Error for Component loading failure (via #261) (@cllns + @solnic)
18
+
19
+ ### Changed
20
+
21
+ - This version uses dry-core 1.0 and dry-configurable 1.0 (@solnic + @flash-gordon)
22
+ - Raise error on import after finalize (via #254) (@timriley + @tak1n)
23
+ - Validate settings even if loader does not set value (via #246) (@oeoeaio)
24
+ - Remove all deprecated functionality and deprecation messages (via #255) (@timriley)
25
+ - Use main dry/monitor entrypoint for autoloading (via #257) (@timriley)
26
+ - Use dry-configurable 1.0 (via 43c79095ccf54c6251e825ae20c97a9415e78209) (@flash-gordon)
27
+ - Use dry-core 1.0 (via 3d0cf95aef120601e67f3e8fbbf16d004017d376) (@flash-gordon)
28
+ - Remove dry-container dependency and update to use `Dry::Core::Container` (via 2b76554e5925fc92614627d5c1e0a9177cecf12f) (@solnic)
29
+
30
+ [Compare v0.27.2...v1.0.0](https://github.com/dry-rb/dry-system/compare/v0.27.2...v1.0.0)
31
+
32
+ ## 0.27.2 2022-10-17
33
+
34
+
35
+ ### Fixed
36
+
37
+ - Removed remaining manual require left-overs (@solnic)
38
+
39
+
40
+ [Compare v0.27.1...v0.27.2](https://github.com/dry-rb/dry-system/compare/v0.27.1...v0.27.2)
41
+
42
+ ## 0.27.1 2022-10-15
43
+
44
+
45
+ ### Fixed
46
+
47
+ - Tweak for zeitwerk loader (@flash-gordon)
48
+
49
+
50
+ [Compare v0.27.0...v0.27.1](https://github.com/dry-rb/dry-system/compare/v0.27.0...v0.27.1)
51
+
52
+ ## 0.27.0 2022-10-15
53
+
54
+
55
+ ### Changed
56
+
57
+ - [BREAKING] Use zeitwerk for auto-loading dry-system (@flash-gordon + @solnic)
58
+
59
+ From now on you need to do `require "dry/system"` as it sets up its Zeitwerk loader and from
60
+ there, everything else will be auto-loaded.
61
+
62
+ [Compare v0.26.0...v0.27.0](https://github.com/dry-rb/dry-system/compare/v0.26.0...v0.27.0)
63
+
64
+ ## 0.26.0 2022-10-08
65
+
66
+
67
+ ### Changed
68
+
69
+ - Update dry-configurable dependency to 0.16.0 and make internal adjustments to suit (@timriley in #249)
70
+ - Remove now-unused concurrent-ruby gem dependency (@timriley in #250)
71
+
72
+ [Compare v0.25.0...v0.26.0](https://github.com/dry-rb/dry-system/compare/v0.25.0...v0.26.0)
73
+
74
+ ## 0.25.0 2022-07-10
75
+
76
+
77
+ ### Fixed
78
+
79
+ - Fix incorrect type in `ManifestRegistrar#finalize!` (@alassek)
80
+
81
+ ### Changed
82
+
83
+ - Import root components via `nil` import namespace (via #236) (@timriley)
84
+ - Allow deeper `Provider::Source` hierarchies (via #240) (@timriley + @solnic)
85
+ - Prefer local components when importing (via #241) (@timriley + @solnic)
86
+
87
+ [Compare v0.24.0...v0.25.0](https://github.com/dry-rb/dry-system/compare/v0.24.0...v0.25.0)
88
+
89
+ ## 0.24.0
90
+
91
+
92
+ ### Changed
93
+
94
+ - dry-struct depedency was removed (@flash-gordon)
95
+
96
+ [Compare v0.23.0...master](https://github.com/dry-rb/dry-system/compare/v0.23.0...master)
97
+
98
+ ## 0.23.0 2022-02-08
99
+
100
+ This is a major overhaul of bootable components (now known as “Providers”), and brings major advancements to other areas, including container imports and exports.
101
+
102
+ Deprecations are in place for otherwise breaking changes to commonly used parts of dry-system, though some breaking changes remain.
103
+
104
+ This prepares the way for dry-system 1.0, which will be released in the coming months.
105
+
106
+
107
+ ### Added
108
+
109
+ - Containers can configure specific components for export using `config.exports` (@timriley in #209).
110
+
111
+ ```ruby
112
+ class MyContainer < Dry::System::Container
113
+ configure do |config|
114
+ config.exports = %w[component_a component_b]
115
+ end
116
+ end
117
+ ```
118
+
119
+ Containers importing another container with configured exports will import only those components.
120
+
121
+ 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.
122
+ - 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)
123
+
124
+ This makes it possible to enable Zeitwerk with a one-liner:
125
+
126
+ ```ruby
127
+ class MyContainer < Dry::System::Container
128
+ use :zeitwerk
129
+
130
+ configure do |config|
131
+ config.component_dirs.add "lib"
132
+ # ...
133
+ end
134
+ end
135
+ ```
136
+
137
+ 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`.
138
+
139
+ The plugin accepts the following options:
140
+
141
+ - `loader:` - (optional) to use a pre-initialized loader, if required.
142
+ - `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.
143
+ - `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`.
144
+ - `debug:` - (optional) a bool to set whether Zeitwerk should log to `$stdout`.
145
+ - New `Identifier#end_with?` and `Identifier#include?` predicates (@timriley in #219)
146
+
147
+ These are key segment-aware predicates that can be useful when checking components as part of container configuration.
148
+
149
+ ```ruby
150
+ identifier.key # => "articles.operations.create"
151
+
152
+ identifier.end_with?("create") # => true
153
+ identifier.end_with?("operations.create") # => true
154
+ identifier.end_with?("ate") # => false, not a whole segment
155
+ identifier.end_with?("nope") # => false, not part of the key at all
156
+
157
+ identifier.include?("operations") # => true
158
+ identifier.include?("articles.operations") # => true
159
+ identifier.include?("operations.create") # => true
160
+ identifier.include?("article") # false, not a whole segment
161
+ identifier.include?("update") # => false, not part of the key at all
162
+ ```
163
+ - An `instance` setting for component dirs allows simpler per-dir control over component instantiation (@timriley in #215)
164
+
165
+ 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.
166
+
167
+ ```ruby
168
+ configure do |config|
169
+ config.component_dirs.add "lib" do |dir|
170
+ dir.instance = proc do |component|
171
+ if component.identifier.include?("workers")
172
+ # Register classes for jobs
173
+ component.loader.constant(component)
174
+ else
175
+ # Otherwise register regular instances per default loader
176
+ component.loader.call(component)
177
+ end
178
+ end
179
+ end
180
+ end
181
+ ```
182
+
183
+ For complete control of component loading, you should continue to configure the component dir’s `loader` instead.
184
+ - 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).
185
+
186
+ The error shows expected and found class names, and inflector configuration that may be required in the case of class names containing acronyms.
187
+
188
+ ### Fixed
189
+
190
+ - 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).
191
+ - Providers can no longer implicitly re-start themselves while in the process of starting and cause an infinite loop (@timriley #213).
192
+
193
+ 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.
194
+
195
+ ### Changed
196
+
197
+ - “Bootable components” (also referred to in some places simply as “components”) have been renamed to “Providers” (@timriley in #200).
198
+
199
+ Register a provider with `Dry::System::Container.register_provider` (`Dry::System::Container.boot` has been deprecated):
200
+
201
+ ```ruby
202
+ MyContainer.register_provider(:mailer) do
203
+ # ...
204
+ end
205
+ ```
206
+ - Provider `init` lifecycle step has been deprecated and renamed to `prepare` (@timriley in #200).
207
+
208
+ ```ruby
209
+ MyContainer.reigster_provider(:mailer) do
210
+ # Rename `init` to `prepare`
211
+ prepare do
212
+ require "some/third_party/mailer"
213
+ end
214
+ end
215
+ ```
216
+ - Provider behavior is now backed by a class per provider, known as the “Provider source” (@timriley in #202).
217
+
218
+ The provider source class is created for each provider as a subclass of `Dry::System::Provider::Source`.
219
+
220
+ 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:
221
+
222
+ ```ruby
223
+ MyContainer.reigster_provider(:mailer) do
224
+ prepare do
225
+ require "some/third_party/mailer"
226
+ @some_config = ThirdParty::Mailer::Config.new
227
+ end
228
+
229
+ start do
230
+ # Since the `prepare` step will always run before start, we can access
231
+ # @some_config here
232
+ register "mailer", ThirdParty::Mailer.new(@some_config)
233
+ end
234
+ end
235
+ ```
236
+
237
+ 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.
238
+
239
+ 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:
240
+
241
+ ```ruby
242
+ MyContainer.register_provider(:mailer, source: Class.new(Dry::System::Provider::Source) {
243
+ # The provider lifecycle steps are ordinary methods
244
+ def prepare
245
+ end
246
+
247
+ def start
248
+ mailer = some_complex_logic_to_build_the_mailer(some: "config")
249
+ register(:mailer, mailer)
250
+ end
251
+
252
+ private
253
+
254
+ def some_complex_logic_to_build_the_mailer(**options)
255
+ # ...
256
+ end
257
+ })
258
+ ```
259
+ - The block argument to `Dry::System::Container.register_provider` (previously `.boot`) has been deprecated. (@timriley in #202).
260
+
261
+ 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).
262
+
263
+ To access the target container, you can use `#target_container` (or `#target` as a convenience alias) instead.
264
+
265
+ 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).
266
+ - `use(provider_name)` inside a provider step has been deprecated. Use `target_container.start(provider_name)` instead (@timriley in #211 and #224)
267
+
268
+ 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)`.
269
+ - `method_missing`-based delegation within providers to target container registrations has been removed (**BREAKING**) (@timriley in #202)
270
+
271
+ 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:
272
+
273
+ ```ruby
274
+ MyContainer.register_provider(:mailer, namespace: true) do
275
+ prepare do
276
+ register :config, "mailer config here"
277
+ end
278
+
279
+ start do
280
+ config # => "mailer config here"
281
+ end
282
+ end
283
+ ```
284
+ - 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).
285
+
286
+ 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):
287
+
288
+ ```ruby
289
+ require "dry/system"
290
+
291
+ Dry::System.register_provider_sources(path)
292
+ ```
293
+
294
+ You can register an individual external provider source via `Dry::System.register_provider_source` (`Dry::System.register_component` has been deprecated):
295
+
296
+ ```ruby
297
+ Dry::System.register_provider_source(:something, group: :my_gem) do
298
+ start do
299
+ # ...
300
+ end
301
+ end
302
+ ```
303
+
304
+ Just like providers, you can also register a class as an external provider source:
305
+
306
+ ```ruby
307
+ module MyGem
308
+ class MySource < Dry::System::Provider::Source
309
+ def start
310
+ # ...
311
+ end
312
+ end
313
+ end
314
+
315
+ Dry::System.register_provider_source(:something, group: :my_gem, source: MyGem::MySource)
316
+ ```
317
+
318
+ 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.
319
+ - Registering a provider using an explicitly named external provider source via `key:` argument is deprecated, use the `source:` argument instead (@timriley in #202).
320
+
321
+ You can register a provider using the same name as an external provider source by specifying the `from:` argument only, as before:
322
+
323
+ ```ruby
324
+ # Elsewhere
325
+ Dry::System.register_provider_source(:something, group: :my_gem) { ... }
326
+
327
+ # In your app:
328
+ MyContainer.register_provider(:something, from: :my_gem)
329
+ ```
330
+
331
+ When you wish the name your provider differently, this is when you need to use the `source:` argument:
332
+
333
+ ```ruby
334
+ MyContainer.register_provider(:differently_named, from: :my_gem, source: :something)
335
+ ```
336
+
337
+ 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.
338
+ - Provider source settings are now defined using dry-configurable’s `setting` API at the top-level scope (@timriley in #202).
339
+
340
+ 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`:
341
+
342
+ ```ruby
343
+ # In the external provider source
344
+ Dry::System.register_provider_source(:something, group: :my_gem) do
345
+ setting :my_option
346
+
347
+ start do
348
+ # Do something with `config.my_option` here
349
+ end
350
+ end
351
+ ```
352
+
353
+ When using an external provider source, configure the source via the `#configure`:
354
+
355
+ ```ruby
356
+ # In your application's provider using the external source
357
+ MyContainer.register_provider(:something, from: :my_gem) do
358
+ configure do |config|
359
+ config.my_option = "some value"
360
+ end
361
+ end
362
+ ```
363
+
364
+ To provide default values and type checking or constraints for your settings, use the dry-configurable’s `default:` and `constructor:` arguments:
365
+
366
+ ```ruby
367
+ # Constructor can take any proc being passed the provided value
368
+ setting :my_option, default: "hello", constructor: -> (v) { v.to_s.upcase }
369
+
370
+ # Constructor will also work with dry-types objects
371
+ setting :my_option, default: "hello", constructor: Types::String.constrained(min_size: 3)
372
+ ```
373
+ - External provider sources can define their own methods for use by the providers alongside lifecycle steps (@timriley in #202).
374
+
375
+ 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:
376
+
377
+ ```ruby
378
+ # In the external provider source
379
+
380
+ module MyGem
381
+ class MySource < Dry::System::Provider::Source
382
+ # Standard lifecycle steps
383
+ def start
384
+ # Do something with @on_start here
385
+ end
386
+
387
+ # Custom behavior available when this provider source is used in a provider
388
+ def on_start(&block)
389
+ @on_start = block
390
+ end
391
+ end
392
+ end
393
+
394
+ Dry::System.register_provider_source(:something, group: :my_gem, source: MyGem::MySource)
395
+
396
+ # In your application's provider using the external source
397
+
398
+ MyContainer.register_provider(:something, from: :my_gem) do
399
+ # Use the custom method!
400
+ on_start do
401
+ # ...
402
+ end
403
+ end
404
+ ```
405
+ - Providers can be registered conditionally using the `if:` option (@timriley in #218).
406
+
407
+ You should provide a simple truthy or falsey value to `if:`, and in the case of falsey value, the provider will not be registered.
408
+
409
+ 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.
410
+ - `bootable_dirs` container setting has been deprecated and replaced by `provider_dirs` (@timriley in #200).
411
+
412
+ The default value for `provider_dirs` is now `"system/providers`".
413
+ - Removed the unused `system_dir` container setting (**BREAKING**) (@timriley in #200)
414
+
415
+ If you’ve configured this inside your container, you can remove it.
416
+ - 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).
417
+ - 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).
418
+
419
+ ```ruby
420
+ MyContainer.register_provider(:settings, from: :dry_system) do
421
+ # ...
422
+ end
423
+ - 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).
424
+
425
+ This `setting` method uses the dry-configurable setting API:
426
+
427
+ ```ruby
428
+ MyContainer.register_provider(:settings, from: :dry_system) do
429
+ settings do
430
+ # Previously:
431
+ # key :my_int_setting, MyTypes::Coercible::Integer
432
+
433
+ # Now:
434
+ setting :my_setting, default: 0, constructor: MyTypes::Coercible::Integer
435
+ end
436
+ end
437
+ ```
438
+ - The `:settings` provider source now requires the dotenv gem to load settings from `.env*` files (**BREAKING**) (@timriley in #204)
439
+
440
+ To ensure you can load your settings from these `.env*` files, add `gem "dotenv"` to your `Gemfile`.
441
+ - `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).
442
+
443
+ 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.
444
+ - `Dry::System::Container.configure(&block)` will now finalize (freeze) the `config` object by default, before returning (@timriley in #207).
445
+
446
+ You can opt out of this behavior by passing the `finalize_config: false` option:
447
+
448
+ ```ruby
449
+ class MyContainer < Dry::System::Container
450
+ configure(finalize_config: false) do |config|
451
+ # ...
452
+ end
453
+
454
+ # `config` is still non-finalized here
455
+ end
456
+ ```
457
+ - `Dry::System::Container.finalize!` will call `.configured!` (if it has not yet been called) before doing its work (@timriley in #207)
458
+
459
+ This ensures config finalization is an intrinsic part of the overall container finalization process.
460
+ - The `Dry::System::Container` `before(:configure)` hook has been removed (**BREAKING**) (@timriley in #207).
461
+
462
+ 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.
463
+ - 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).
464
+
465
+ This ensures the plugin settings are available immediately after you’ve enabled the plugin via `Dry::System::Container.use`.
466
+ - 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)
467
+ - 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)
468
+
469
+ To import specific components:
470
+
471
+ ```ruby
472
+ class MyContainer < Dry::System::Container
473
+ # config, etc.
474
+
475
+ # Will import components with keys "other.component_a", "other.component_b"
476
+ import(
477
+ keys: %w[component_a component_b],
478
+ from: OtherContainer,
479
+ as: :other
480
+ )
481
+ ```
482
+
483
+ Omitting `keys:` will import all the components available from the other container.
484
+ - Components imported into a container from another will be protected from subsequent export unless explicitly configured in `config.exports` (@timriley in #209)
485
+
486
+ Imported components are considered “private” by default because they did not originate in container that imported them.
487
+
488
+ 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.
489
+ - Container imports are now made without finalizing the exporting container in most cases, ensuring more efficient imports (@timriley in #209)
490
+
491
+ 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`.
492
+ - [Internal] The `manual_registrar` container setting and associated `ManualRegistrar` class have been renamed to `manifest_registrar` and `ManifestRegistrar` respectively (**BREAKING**) (@timriley in #208).
493
+ - The default value for the container `registrations_dir` setting has been changed from `"container"` to `"system/registrations"` (**BREAKING**) (@timriley in #208)
494
+ - The `:dependency_graph` plugin now supports all dry-auto_inject injector strategies (@davydovanton and @timriley in #214)
495
+
496
+ [Compare v0.22.0...v0.23.0](https://github.com/dry-rb/dry-system/compare/v0.22.0...v0.23.0)
497
+
498
+ ## 0.22.0 2022-01-06
499
+
500
+
501
+ ### Added
502
+
503
+ - Expanded public interfaces for `Dry::System::Config::ComponentDirs` and `Dry::System::Config::Namespaces` to better support programmatic construction and inspection of these configs (@timriley in #195)
504
+
505
+ ### Changed
506
+
507
+ - Deprecated `Dry::System::Config::Namespaces#root` as the way to add and configure a root namespace. Use `#add_root` instead (@timriley in #195)
508
+ - Allow bootsnap plugin to use bootsnap on Ruby versions up to 3.0 (pusewicz in #196)
509
+
510
+ [Compare v0.21.0...v0.22.0](https://github.com/dry-rb/dry-system/compare/v0.21.0...v0.22.0)
511
+
512
+ ## 0.21.0 2021-11-01
513
+
514
+
515
+ ### Added
516
+
517
+ - Added **component dir namespaces** as a way to specify multiple, ordered, independent namespace rules within a given component dir. This replaces and expands upon the namespace support we previously provided via the singular `default_namespace` component dir setting (@timriley in #181)
518
+
519
+ ### Changed
520
+
521
+ - `default_namespace` setting on component dirs has been deprecated. Add a component dir namespace instead, e.g. instead of:
522
+
523
+ ```ruby
524
+ # Inside Dry::System::Container.configure
525
+ config.component_dirs.add "lib" do |dir|
526
+ dir.default_namespace = "admin"
527
+ end
528
+ ```
529
+
530
+ Add this:
531
+
532
+ ```ruby
533
+ config.component_dirs.add "lib" do |dir|
534
+ dir.namespaces.add "admin", key: nil
535
+ end
536
+ ```
537
+
538
+ (@timriley in #181)
539
+ - `Dry::System::Component#path` has been removed and replaced by `Component#require_path` and `Component#const_path` (@timriley in #181)
540
+ - Unused `Dry::System::FileNotFoundError` and `Dry::System::InvalidComponentIdentifierTypeError` errors have been removed (@timriley in #194)
541
+ - Allow bootsnap for Rubies up to 3.0.x (via #196) (@pusewicz)
542
+
543
+ [Compare v0.20.0...v0.21.0](https://github.com/dry-rb/dry-system/compare/v0.20.0...v0.21.0)
544
+
545
+ ## 0.20.0 2021-09-12
546
+
547
+
548
+ ### Fixed
549
+
550
+ - Fixed dependency graph plugin to work with internal changes introduced in 0.19.0 (@wuarmin in #173)
551
+ - Fixed behavior of `Dry::System::Identifier#start_with?` for components identified by a single segment, or if all matching segments are provided (@wuarmin in #177)
552
+ - Fixed compatibility of `finalize!` signature provided in `Container::Stubs` (@mpokrywka in #178)
553
+
554
+ ### Changed
555
+
556
+ - [internal] Upgraded to new `setting` API provided in dry-configurable 0.13.0 (@timriley in #179)
557
+
558
+ [Compare v0.19.2...v0.20.0](https://github.com/dry-rb/dry-system/compare/v0.19.2...v0.20.0)
559
+
560
+ ## 0.19.2 2021-08-30
561
+
562
+
563
+ ### Changed
564
+
565
+ - [internal] Improved compatibility with upcoming dry-configurable 0.13.0 release (@timriley in #186)
566
+
567
+ [Compare v0.18.2...v0.19.2](https://github.com/dry-rb/dry-system/compare/v0.18.2...v0.19.2)
568
+
569
+ ## 0.18.2 2021-08-30
570
+
571
+
572
+ ### Changed
573
+
574
+ - [internal] Improved compatibility with upcoming dry-configurable 0.13.0 release (@timriley in #187)
575
+
576
+ [Compare v0.19.1...v0.18.2](https://github.com/dry-rb/dry-system/compare/v0.19.1...v0.18.2)
577
+
578
+ ## 0.19.1 2021-07-11
579
+
580
+
581
+ ### Fixed
582
+
583
+ - Check for registered components (@timriley in #175)
584
+
585
+
586
+ [Compare v0.19.0...v0.19.1](https://github.com/dry-rb/dry-system/compare/v0.19.0...v0.19.1)
587
+
588
+ ## 0.19.0 2021-04-22
589
+
590
+ This release marks a huge step forward for dry-system, bringing support for Zeitwerk and other autoloaders, plus clearer configuration and improved consistency around component resolution for both finalized and lazy loading containers. [Read the announcement post](https://dry-rb.org/news/2021/04/22/dry-system-0-19-released-with-zeitwerk-support-and-more-leading-the-way-for-hanami-2-0/) for a high-level tour of the new features.
591
+
592
+ ### Added
593
+
594
+ - New `component_dirs` setting on `Dry::System::Container`, which must be used for specifying the directories which dry-system will search for component source files.
595
+
596
+ Each added component dir is relative to the container's `root`, and can have its own set of settings configured:
597
+
598
+ ```ruby
599
+ class MyApp::Container < Dry::System::Container
600
+ configure do |config|
601
+ config.root = __dir__
602
+
603
+ # Defaults for all component dirs can be configured separately
604
+ config.component_dirs.auto_register = true # default is already true
605
+
606
+ # Component dirs can be added and configured independently
607
+ config.component_dirs.add "lib" do |dir|
608
+ dir.add_to_load_path = true # defaults to true
609
+ dir.default_namespace = "my_app"
610
+ end
611
+
612
+ # All component dir settings are optional. Component dirs relying on default
613
+ # settings can be added like so:
614
+ config.component_dirs.add "custom_components"
615
+ end
616
+ end
617
+ ```
618
+
619
+ The following settings are available for configuring added `component_dirs`:
620
+
621
+ - `auto_register`, a boolean, or a proc accepting a `Dry::System::Component` instance and returning a truthy or falsey value. Providing a proc allows an auto-registration policy to apply on a per-component basis
622
+ - `add_to_load_path`, a boolean
623
+ - `default_namespace`, a string representing the leading namespace segments to be stripped from the component's identifier (given the identifier is derived from the component's fully qualified class name)
624
+ - `loader`, a custom replacement for the default `Dry::System::Loader` to be used for the component dir
625
+ - `memoize`, a boolean, to enable/disable memoizing all components in the directory, or a proc accepting a `Dry::System::Component` instance and returning a truthy or falsey value. Providing a proc allows a memoization policy to apply on a per-component basis
626
+
627
+ _All component dir settings are optional._
628
+
629
+ (@timriley in #155, #157, and #162)
630
+ - A new autoloading-friendly `Dry::System::Loader::Autoloading` is available, which is tested to work with [Zeitwerk](https://github.com/fxn/zeitwerk) 🎉
631
+
632
+ Configure this on the container (via a component dir `loader` setting), and the loader will no longer `require` any components, instead allowing missing constant resolution to trigger the loading of the required file.
633
+
634
+ This loader presumes an autoloading system like Zeitwerk has already been enabled and appropriately configured.
635
+
636
+ A recommended setup is as follows:
637
+
638
+ ```ruby
639
+ require "dry/system/container"
640
+ require "dry/system/loader/autoloading"
641
+ require "zeitwerk"
642
+
643
+ class MyApp::Container < Dry::System::Container
644
+ configure do |config|
645
+ config.root = __dir__
646
+
647
+ config.component_dirs.loader = Dry::System::Loader::Autoloading
648
+ config.component_dirs.add_to_load_path = false
649
+
650
+ config.component_dirs.add "lib" do |dir|
651
+ # ...
652
+ end
653
+ end
654
+ end
655
+
656
+ loader = Zeitwerk::Loader.new
657
+ loader.push_dir MyApp::Container.config.root.join("lib").realpath
658
+ loader.setup
659
+ ```
660
+
661
+ (@timriley in #153)
662
+ - [BREAKING] `Dry::System::Component` instances (which users of dry-system will interact with via custom loaders, as well as via the `auto_register` and `memoize` component dir settings described above) now return a `Dry::System::Identifier` from their `#identifier` method. The raw identifier string may be accessed via the identifier's own `#key` or `#to_s` methods. `Identifier` also provides a helpful namespace-aware `#start_with?` method for returning whether the identifier begins with the provided namespace(s) (@timriley in #158)
663
+
664
+ ### Changed
665
+
666
+ - Components with `# auto_register: false` magic comments in their source files are now properly ignored when lazy loading (@timriley in #155)
667
+ - `# memoize: true` and `# memoize: false` magic comments at top of component files are now respected (@timriley in #155)
668
+ - [BREAKING] `Dry::System::Container.load_paths!` has been renamed to `.add_to_load_path!`. This method now exists as a mere convenience only. Calling this method is no longer required for any configured `component_dirs`; these are now added to the load path automatically (@timriley in #153 and #155)
669
+ - [BREAKING] `auto_register` container setting has been removed. Configured directories to be auto-registered by adding `component_dirs` instead (@timriley in #155)
670
+ - [BREAKING] `default_namespace` container setting has been removed. Set it when adding `component_dirs` instead (@timriley in #155)
671
+ - [BREAKING] `loader` container setting has been nested under `component_dirs`, now available as `component_dirs.loader` to configure a default loader for all component dirs, as well as on individual component dirs when being added (@timriley in #162)
672
+ - [BREAKING] `Dry::System::ComponentLoadError` is no longer raised when a component could not be lazy loaded; this was only raised in a single specific failure condition. Instead, a `Dry::Container::Error` is raised in all cases of components failing to load (@timriley in #155)
673
+ - [BREAKING] `Dry::System::Container.auto_register!` has been removed. Configure `component_dirs` instead. (@timriley in #157)
674
+ - [BREAKING] The `Dry::System::Loader` interface has changed. It is now a static interface, no longer initialized with a component. The component is instead passed to each method as an argument: `.require!(component)`, `.call(component, *args)`, `.constant(component)` (@timriley in #157)
675
+ - [BREAKING] `Dry::System::Container.require_path` has been removed. Provide custom require behavior by configuring your own `loader` (@timriley in #153)
676
+
677
+ [Compare v0.18.1...v0.19.0](https://github.com/dry-rb/dry-system/compare/v0.18.1...v0.19.0)
678
+
1
679
  ## 0.18.1 2020-08-26
2
680
 
3
681
 
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2020 dry-rb team
3
+ Copyright (c) 2015-2022 dry-rb 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