dry-system 0.22.0 → 0.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +400 -0
  3. data/LICENSE +1 -1
  4. data/README.md +2 -2
  5. data/dry-system.gemspec +2 -2
  6. data/lib/dry/system/component.rb +2 -3
  7. data/lib/dry/system/component_dir.rb +8 -34
  8. data/lib/dry/system/components.rb +8 -4
  9. data/lib/dry/system/config/component_dir.rb +60 -16
  10. data/lib/dry/system/config/component_dirs.rb +23 -10
  11. data/lib/dry/system/config/namespace.rb +4 -6
  12. data/lib/dry/system/constants.rb +1 -1
  13. data/lib/dry/system/container.rb +264 -182
  14. data/lib/dry/system/errors.rb +73 -53
  15. data/lib/dry/system/identifier.rb +62 -20
  16. data/lib/dry/system/importer.rb +83 -12
  17. data/lib/dry/system/indirect_component.rb +1 -1
  18. data/lib/dry/system/loader.rb +6 -1
  19. data/lib/dry/system/{manual_registrar.rb → manifest_registrar.rb} +8 -5
  20. data/lib/dry/system/plugins/bootsnap.rb +2 -1
  21. data/lib/dry/system/plugins/dependency_graph/strategies.rb +37 -1
  22. data/lib/dry/system/plugins/dependency_graph.rb +26 -20
  23. data/lib/dry/system/plugins/env.rb +2 -1
  24. data/lib/dry/system/plugins/logging.rb +2 -2
  25. data/lib/dry/system/plugins/monitoring.rb +1 -1
  26. data/lib/dry/system/plugins/notifications.rb +1 -1
  27. data/lib/dry/system/plugins/zeitwerk/compat_inflector.rb +22 -0
  28. data/lib/dry/system/plugins/zeitwerk.rb +109 -0
  29. data/lib/dry/system/plugins.rb +7 -4
  30. data/lib/dry/system/provider/source.rb +324 -0
  31. data/lib/dry/system/provider/source_dsl.rb +94 -0
  32. data/lib/dry/system/provider.rb +262 -22
  33. data/lib/dry/system/provider_registrar.rb +276 -0
  34. data/lib/dry/system/provider_source_registry.rb +70 -0
  35. data/lib/dry/system/provider_sources/settings/config.rb +86 -0
  36. data/lib/dry/system/provider_sources/settings/loader.rb +53 -0
  37. data/lib/dry/system/provider_sources/settings.rb +40 -0
  38. data/lib/dry/system/provider_sources.rb +5 -0
  39. data/lib/dry/system/version.rb +1 -1
  40. data/lib/dry/system.rb +44 -12
  41. metadata +18 -18
  42. data/lib/dry/system/booter/component_registry.rb +0 -35
  43. data/lib/dry/system/booter.rb +0 -200
  44. data/lib/dry/system/components/bootable.rb +0 -280
  45. data/lib/dry/system/components/config.rb +0 -35
  46. data/lib/dry/system/lifecycle.rb +0 -135
  47. data/lib/dry/system/provider_registry.rb +0 -27
  48. data/lib/dry/system/settings/file_loader.rb +0 -30
  49. data/lib/dry/system/settings/file_parser.rb +0 -51
  50. data/lib/dry/system/settings.rb +0 -64
  51. 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: 2ce0d3b9c3094e2e7d1b20907a31107d6329221e6213839708f8cc7bac1321bd
4
- data.tar.gz: 2e28bfe4758cace04f1978c2b17fa138921915d5db0b894796772fa428e12549
3
+ metadata.gz: 1719add7d103e13ec062de6515d40d9d47bda60e7e70a063649a111b1c00e4ef
4
+ data.tar.gz: 804f75708ddfc1083a63198a12fcc84226c70ab5e8dd6fd80bca1516831ab0eb
5
5
  SHA512:
6
- metadata.gz: 33e7e5e5cccf47481498a95c8dc37fdb282ab9005c595f4db30b05f84c842d5144ba7cfa0f3a15f895212dbb0034554f36d16649d004bf54eebc99dca70d53d1
7
- data.tar.gz: dc441f94a5d1506e7c7bc4afd9e8ebfd43d43e7956af09e2a793df6d1b02b409ac8eb0252183cae6c388969f2e33b02522675794c1aa4c340f6c52efa0ad7344
6
+ metadata.gz: 3ef24909abb786c3faafcd9fedfc37fb5ef715bed3128243a523e7046171b70fc70b0c8d21bdc1d9ea005f22f3e2bb2129834d99d0f606b699f909b09d78e1ae
7
+ data.tar.gz: 588331f0d24e87414f0b182d855a74a05adc5f33303d79ad8ed98293f7a18de7e9f513218cca672d5ff394369adbaf0543be4375c92cd6c391595dadda446039
data/CHANGELOG.md CHANGED
@@ -1,5 +1,405 @@
1
1
  <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
2
 
3
+ ## 0.23.0 2022-02-08
4
+
5
+ This is a major overhaul of bootable components (now known as “Providers”), and brings major advancements to other areas, including container imports and exports.
6
+
7
+ Deprecations are in place for otherwise breaking changes to commonly used parts of dry-system, though some breaking changes remain.
8
+
9
+ This prepares the way for dry-system 1.0, which will be released in the coming months.
10
+
11
+
12
+ ### Added
13
+
14
+ - Containers can configure specific components for export using `config.exports` (@timriley in #209).
15
+
16
+ ```ruby
17
+ class MyContainer < Dry::System::Container
18
+ configure do |config|
19
+ config.exports = %w[component_a component_b]
20
+ end
21
+ end
22
+ ```
23
+
24
+ Containers importing another container with configured exports will import only those components.
25
+
26
+ 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.
27
+ - 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)
28
+
29
+ This makes it possible to enable Zeitwerk with a one-liner:
30
+
31
+ ```ruby
32
+ class MyContainer < Dry::System::Container
33
+ use :zeitwerk
34
+
35
+ configure do |config|
36
+ config.component_dirs.add "lib"
37
+ # ...
38
+ end
39
+ end
40
+ ```
41
+
42
+ 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`.
43
+
44
+ The plugin accepts the following options:
45
+
46
+ - `loader:` - (optional) to use a pre-initialized loader, if required.
47
+ - `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.
48
+ - `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`.
49
+ - `debug:` - (optional) a bool to set whether Zeitwerk should log to `$stdout`.
50
+ - New `Identifier#end_with?` and `Identifier#include?` predicates (@timriley in #219)
51
+
52
+ These are key segment-aware predicates that can be useful when checking components as part of container configuration.
53
+
54
+ ```ruby
55
+ identifier.key # => "articles.operations.create"
56
+
57
+ identifier.end_with?("create") # => true
58
+ identifier.end_with?("operations.create") # => true
59
+ identifier.end_with?("ate") # => false, not a whole segment
60
+ identifier.end_with?("nope") # => false, not part of the key at all
61
+
62
+ identifier.include?("operations") # => true
63
+ identifier.include?("articles.operations") # => true
64
+ identifier.include?("operations.create") # => true
65
+ identifier.include?("article") # false, not a whole segment
66
+ identifier.include?("update") # => false, not part of the key at all
67
+ ```
68
+ - An `instance` setting for component dirs allows simpler per-dir control over component instantiation (@timriley in #215)
69
+
70
+ 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.
71
+
72
+ ```ruby
73
+ configure do |config|
74
+ config.component_dirs.add "lib" do |dir|
75
+ dir.instance = proc do |component|
76
+ if component.identifier.include?("workers")
77
+ # Register classes for jobs
78
+ component.loader.constant(component)
79
+ else
80
+ # Otherwise register regular instances per default loader
81
+ component.loader.call(component)
82
+ end
83
+ end
84
+ end
85
+ end
86
+ ```
87
+
88
+ For complete control of component loading, you should continue to configure the component dir’s `loader` instead.
89
+ - 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).
90
+
91
+ The error shows expected and found class names, and inflector configuration that may be required in the case of class names containing acronyms.
92
+
93
+ ### Fixed
94
+
95
+ - 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).
96
+ - Providers can no longer implicitly re-start themselves while in the process of starting and cause an infinite loop (@timriley #213).
97
+
98
+ 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.
99
+
100
+ ### Changed
101
+
102
+ - “Bootable components” (also referred to in some places simply as “components”) have been renamed to “Providers” (@timriley in #200).
103
+
104
+ Register a provider with `Dry::System::Container.register_provider` (`Dry::System::Container.boot` has been deprecated):
105
+
106
+ ```ruby
107
+ MyContainer.register_provider(:mailer) do
108
+ # ...
109
+ end
110
+ ```
111
+ - Provider `init` lifecycle step has been deprecated and renamed to `prepare` (@timriley in #200).
112
+
113
+ ```ruby
114
+ MyContainer.reigster_provider(:mailer) do
115
+ # Rename `init` to `prepare`
116
+ prepare do
117
+ require "some/third_party/mailer"
118
+ end
119
+ end
120
+ ```
121
+ - Provider behavior is now backed by a class per provider, known as the “Provider source” (@timriley in #202).
122
+
123
+ The provider source class is created for each provider as a subclass of `Dry::System::Provider::Source`.
124
+
125
+ 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:
126
+
127
+ ```ruby
128
+ MyContainer.reigster_provider(:mailer) do
129
+ prepare do
130
+ require "some/third_party/mailer"
131
+ @some_config = ThirdParty::Mailer::Config.new
132
+ end
133
+
134
+ start do
135
+ # Since the `prepare` step will always run before start, we can access
136
+ # @some_config here
137
+ register "mailer", ThirdParty::Mailer.new(@some_config)
138
+ end
139
+ end
140
+ ```
141
+
142
+ 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.
143
+
144
+ 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:
145
+
146
+ ```ruby
147
+ MyContainer.register_provider(:mailer, source: Class.new(Dry::System::Provider::Source) {
148
+ # The provider lifecycle steps are ordinary methods
149
+ def prepare
150
+ end
151
+
152
+ def start
153
+ mailer = some_complex_logic_to_build_the_mailer(some: "config")
154
+ register(:mailer, mailer)
155
+ end
156
+
157
+ private
158
+
159
+ def some_complex_logic_to_build_the_mailer(**options)
160
+ # ...
161
+ end
162
+ })
163
+ ```
164
+ - The block argument to `Dry::System::Container.register_provider` (previously `.boot`) has been deprecated. (@timriley in #202).
165
+
166
+ 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).
167
+
168
+ To access the target container, you can use `#target_container` (or `#target` as a convenience alias) instead.
169
+
170
+ 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).
171
+ - `use(provider_name)` inside a provider step has been deprecated. Use `target_container.start(provider_name)` instead (@timriley in #211 and #224)
172
+
173
+ 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)`.
174
+ - `method_missing`-based delegation within providers to target container registrations has been removed (**BREAKING**) (@timriley in #202)
175
+
176
+ 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:
177
+
178
+ ```ruby
179
+ MyContainer.register_provider(:mailer, namespace: true) do
180
+ prepare do
181
+ register :config, "mailer config here"
182
+ end
183
+
184
+ start do
185
+ config # => "mailer config here"
186
+ end
187
+ end
188
+ ```
189
+ - 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).
190
+
191
+ 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):
192
+
193
+ ```ruby
194
+ require "dry/system"
195
+
196
+ Dry::System.register_provider_sources(path)
197
+ ```
198
+
199
+ You can register an individual external provider source via `Dry::System.register_provider_source` (`Dry::System.register_component` has been deprecated):
200
+
201
+ ```ruby
202
+ Dry::System.register_provider_source(:something, group: :my_gem) do
203
+ start do
204
+ # ...
205
+ end
206
+ end
207
+ ```
208
+
209
+ Just like providers, you can also register a class as an external provider source:
210
+
211
+ ```ruby
212
+ module MyGem
213
+ class MySource < Dry::System::Provider::Source
214
+ def start
215
+ # ...
216
+ end
217
+ end
218
+ end
219
+
220
+ Dry::System.register_provider_source(:something, group: :my_gem, source: MyGem::MySource)
221
+ ```
222
+
223
+ 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.
224
+ - Registering a provider using an explicitly named external provider source via `key:` argument is deprecated, use the `source:` argument instead (@timriley in #202).
225
+
226
+ You can register a provider using the same name as an external provider source by specifying the `from:` argument only, as before:
227
+
228
+ ```ruby
229
+ # Elsewhere
230
+ Dry::System.register_provider_source(:something, group: :my_gem) { ... }
231
+
232
+ # In your app:
233
+ MyContainer.register_provider(:something, from: :my_gem)
234
+ ```
235
+
236
+ When you wish the name your provider differently, this is when you need to use the `source:` argument:
237
+
238
+ ```ruby
239
+ MyContainer.register_provider(:differently_named, from: :my_gem, source: :something)
240
+ ```
241
+
242
+ 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.
243
+ - Provider source settings are now defined using dry-configurable’s `setting` API at the top-level scope (@timriley in #202).
244
+
245
+ 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`:
246
+
247
+ ```ruby
248
+ # In the external provider source
249
+ Dry::System.register_provider_source(:something, group: :my_gem) do
250
+ setting :my_option
251
+
252
+ start do
253
+ # Do something with `config.my_option` here
254
+ end
255
+ end
256
+ ```
257
+
258
+ When using an external provider source, configure the source via the `#configure`:
259
+
260
+ ```ruby
261
+ # In your application's provider using the external source
262
+ MyContainer.register_provider(:something, from: :my_gem) do
263
+ configure do |config|
264
+ config.my_option = "some value"
265
+ end
266
+ end
267
+ ```
268
+
269
+ To provide default values and type checking or constraints for your settings, use the dry-configurable’s `default:` and `constructor:` arguments:
270
+
271
+ ```ruby
272
+ # Constructor can take any proc being passed the provided value
273
+ setting :my_option, default: "hello", constructor: -> (v) { v.to_s.upcase }
274
+
275
+ # Constructor will also work with dry-types objects
276
+ setting :my_option, default: "hello", constructor: Types::String.constrained(min_size: 3)
277
+ ```
278
+ - External provider sources can define their own methods for use by the providers alongside lifecycle steps (@timriley in #202).
279
+
280
+ 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:
281
+
282
+ ```ruby
283
+ # In the external provider source
284
+
285
+ module MyGem
286
+ class MySource < Dry::System::Provider::Source
287
+ # Standard lifecycle steps
288
+ def start
289
+ # Do something with @on_start here
290
+ end
291
+
292
+ # Custom behavior available when this provider source is used in a provider
293
+ def on_start(&block)
294
+ @on_start = block
295
+ end
296
+ end
297
+ end
298
+
299
+ Dry::System.register_provider_source(:something, group: :my_gem, source: MyGem::MySource)
300
+
301
+ # In your application's provider using the external source
302
+
303
+ MyContainer.register_provider(:something, from: :my_gem) do
304
+ # Use the custom method!
305
+ on_start do
306
+ # ...
307
+ end
308
+ end
309
+ ```
310
+ - Providers can be registered conditionally using the `if:` option (@timriley in #218).
311
+
312
+ You should provide a simple truthy or falsey value to `if:`, and in the case of falsey value, the provider will not be registered.
313
+
314
+ 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.
315
+ - `bootable_dirs` container setting has been deprecated and replaced by `provider_dirs` (@timriley in #200).
316
+
317
+ The default value for `provider_dirs` is now `"system/providers`".
318
+ - Removed the unused `system_dir` container setting (**BREAKING**) (@timriley in #200)
319
+
320
+ If you’ve configured this inside your container, you can remove it.
321
+ - 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).
322
+ - 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).
323
+
324
+ ```ruby
325
+ MyContainer.register_provider(:settings, from: :dry_system) do
326
+ # ...
327
+ end
328
+ - 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).
329
+
330
+ This `setting` method uses the dry-configurable setting API:
331
+
332
+ ```ruby
333
+ MyContainer.register_provider(:settings, from: :dry_system) do
334
+ settings do
335
+ # Previously:
336
+ # key :my_int_setting, MyTypes::Coercible::Integer
337
+
338
+ # Now:
339
+ setting :my_setting, default: 0, constructor: MyTypes::Coercible::Integer
340
+ end
341
+ end
342
+ ```
343
+ - The `:settings` provider source now requires the dotenv gem to load settings from `.env*` files (**BREAKING**) (@timriley in #204)
344
+
345
+ To ensure you can load your settings from these `.env*` files, add `gem "dotenv"` to your `Gemfile`.
346
+ - `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).
347
+
348
+ 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.
349
+ - `Dry::System::Container.configure(&block)` will now finalize (freeze) the `config` object by default, before returning (@timriley in #207).
350
+
351
+ You can opt out of this behavior by passing the `finalize_config: false` option:
352
+
353
+ ```ruby
354
+ class MyContainer < Dry::System::Container
355
+ configure(finalize_config: false) do |config|
356
+ # ...
357
+ end
358
+
359
+ # `config` is still non-finalized here
360
+ end
361
+ ```
362
+ - `Dry::System::Container.finalize!` will call `.configured!` (if it has not yet been called) before doing its work (@timriley in #207)
363
+
364
+ This ensures config finalization is an intrinsic part of the overall container finalization process.
365
+ - The `Dry::System::Container` `before(:configure)` hook has been removed (**BREAKING**) (@timriley in #207).
366
+
367
+ 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.
368
+ - 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).
369
+
370
+ This ensures the plugin settings are available immediately after you’ve enabled the plugin via `Dry::System::Container.use`.
371
+ - 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)
372
+ - 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)
373
+
374
+ To import specific components:
375
+
376
+ ```ruby
377
+ class MyContainer < Dry::System::Container
378
+ # config, etc.
379
+
380
+ # Will import components with keys "other.component_a", "other.component_b"
381
+ import(
382
+ keys: %w[component_a component_b],
383
+ from: OtherContainer,
384
+ as: :other
385
+ )
386
+ ```
387
+
388
+ Omitting `keys:` will import all the components available from the other container.
389
+ - Components imported into a container from another will be protected from subsequent export unless explicitly configured in `config.exports` (@timriley in #209)
390
+
391
+ Imported components are considered “private” by default because they did not originate in container that imported them.
392
+
393
+ 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.
394
+ - Container imports are now made without finalizing the exporting container in most cases, ensuring more efficient imports (@timriley in #209)
395
+
396
+ 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`.
397
+ - [Internal] The `manual_registrar` container setting and associated `ManualRegistrar` class have been renamed to `manifest_registrar` and `ManifestRegistrar` respectively (**BREAKING**) (@timriley in #208).
398
+ - The default value for the container `registrations_dir` setting has been changed from `"container"` to `"system/registrations"` (**BREAKING**) (@timriley in #208)
399
+ - The `:dependency_graph` plugin now supports all dry-auto_inject injector strategies (@davydovanton and @timriley in #214)
400
+
401
+ [Compare v0.22.0...v0.23.0](https://github.com/dry-rb/dry-system/compare/v0.22.0...v0.23.0)
402
+
3
403
  ## 0.22.0 2022-01-06
4
404
 
5
405
 
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2021 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
data/README.md CHANGED
@@ -22,8 +22,8 @@
22
22
 
23
23
  This library officially supports the following Ruby versions:
24
24
 
25
- * MRI `>= 2.6.0`
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
@@ -26,12 +26,12 @@ Gem::Specification.new do |spec|
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.6.0"
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.13", ">= 0.13.0"
34
+ spec.add_runtime_dependency "dry-configurable", "~> 0.14", ">= 0.14.0"
35
35
  spec.add_runtime_dependency "dry-container", "~> 0.9", ">= 0.9.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"
@@ -20,7 +20,6 @@ module Dry
20
20
  include Dry::Equalizer(:identifier, :namespace, :options)
21
21
 
22
22
  DEFAULT_OPTIONS = {
23
- separator: DEFAULT_SEPARATOR,
24
23
  inflector: Dry::Inflector.new,
25
24
  loader: Loader
26
25
  }.freeze
@@ -61,7 +60,7 @@ module Dry
61
60
  # @return [Object] component's class instance
62
61
  # @api public
63
62
  def instance(*args)
64
- loader.call(self, *args)
63
+ options[:instance]&.call(self, *args) || loader.call(self, *args)
65
64
  end
66
65
  ruby2_keywords(:instance) if respond_to?(:ruby2_keywords, true)
67
66
 
@@ -137,7 +136,7 @@ module Dry
137
136
  #
138
137
  # @api public
139
138
  def const_path
140
- namespace_const_path = namespace.const&.gsub(identifier.separator, PATH_SEPARATOR)
139
+ namespace_const_path = namespace.const&.gsub(KEY_SEPARATOR, PATH_SEPARATOR)
141
140
 
142
141
  if namespace_const_path
143
142
  "#{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, separator: container.config.namespace_separator)
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(separator)
107
+ .join(KEY_SEPARATOR)
135
108
 
136
- identifier = Identifier.new(key, separator: separator)
109
+ identifier = Identifier.new(key)
137
110
  .namespaced(
138
- from: namespace.path&.gsub(PATH_SEPARATOR, separator),
111
+ from: namespace.path&.gsub(PATH_SEPARATOR, KEY_SEPARATOR),
139
112
  to: namespace.key
140
113
  )
141
114
 
@@ -175,6 +148,7 @@ module Dry
175
148
  {
176
149
  auto_register: auto_register,
177
150
  loader: loader,
151
+ instance: instance,
178
152
  memoize: memoize
179
153
  }
180
154
  end
@@ -1,8 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/system"
3
+ require "dry/core/deprecations"
4
4
 
5
- Dry::System.register_provider(
6
- :system,
7
- boot_path: Pathname(__dir__).join("system_components").realpath
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"