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
@@ -20,7 +20,7 @@ module Dry
|
|
20
20
|
# Sets the auto-registration policy for the component dir.
|
21
21
|
#
|
22
22
|
# This may be a simple boolean to enable or disable auto-registration for all
|
23
|
-
# components, or a proc accepting a
|
23
|
+
# components, or a proc accepting a {Dry::System::Component} and returning a
|
24
24
|
# boolean to configure auto-registration on a per-component basis
|
25
25
|
#
|
26
26
|
# Defaults to `true`.
|
@@ -50,30 +50,48 @@ module Dry
|
|
50
50
|
# @api public
|
51
51
|
setting :auto_register, default: true
|
52
52
|
|
53
|
-
# @!method
|
53
|
+
# @!method instance=(instance_proc)
|
54
54
|
#
|
55
|
-
# Sets
|
56
|
-
#
|
55
|
+
# Sets a proc used to return the instance of any component within the component
|
56
|
+
# dir.
|
57
57
|
#
|
58
|
-
#
|
59
|
-
#
|
58
|
+
# This proc should accept a {Dry::System::Component} and return the object to
|
59
|
+
# serve as the component's instance.
|
60
60
|
#
|
61
|
-
#
|
62
|
-
#
|
61
|
+
# When you provide an instance proc, it will be used in preference to the
|
62
|
+
# {loader} (either the default loader or an explicitly configured one). Provide
|
63
|
+
# an instance proc when you want a simple way to customize the instance for
|
64
|
+
# certain components. For complete control, provide a replacement loader via
|
65
|
+
# {loader=}.
|
63
66
|
#
|
64
|
-
#
|
65
|
-
#
|
67
|
+
# Defaults to `nil`.
|
68
|
+
#
|
69
|
+
# @param instance_proc [Proc, nil]
|
70
|
+
# @return [Proc]
|
71
|
+
#
|
72
|
+
# @example
|
73
|
+
# dir.instance = proc do |component|
|
74
|
+
# if component.key.match?(/workers\./)
|
75
|
+
# # Register classes for jobs
|
76
|
+
# component.loader.constant(component)
|
77
|
+
# else
|
78
|
+
# # Otherwise register regular instances per default loader
|
79
|
+
# component.loader.call(component)
|
80
|
+
# end
|
81
|
+
# end
|
82
|
+
#
|
83
|
+
# @see Component, Loader
|
66
84
|
# @api public
|
67
85
|
#
|
68
|
-
# @!method
|
86
|
+
# @!method instance
|
69
87
|
#
|
70
|
-
# Returns the configured
|
88
|
+
# Returns the configured instance proc.
|
71
89
|
#
|
72
|
-
# @return [
|
90
|
+
# @return [Proc, nil]
|
73
91
|
#
|
74
|
-
# @see
|
92
|
+
# @see instance=
|
75
93
|
# @api public
|
76
|
-
setting :
|
94
|
+
setting :instance
|
77
95
|
|
78
96
|
# @!method loader=(loader)
|
79
97
|
#
|
@@ -82,7 +100,8 @@ module Dry
|
|
82
100
|
#
|
83
101
|
# Defaults to `Dry::System::Loader`.
|
84
102
|
#
|
85
|
-
# When using
|
103
|
+
# When using an autoloader like Zeitwerk, consider using
|
104
|
+
# `Dry::System::Loader::Autoloading`
|
86
105
|
#
|
87
106
|
# @param loader [#call] the loader
|
88
107
|
# @return [#call] the configured loader
|
@@ -150,6 +169,31 @@ module Dry
|
|
150
169
|
# @api public
|
151
170
|
setting :namespaces, default: Namespaces.new, cloneable: true
|
152
171
|
|
172
|
+
# @!method add_to_load_path=(policy)
|
173
|
+
#
|
174
|
+
# Sets whether the dir should be added to the `$LOAD_PATH` after the container
|
175
|
+
# is configured.
|
176
|
+
#
|
177
|
+
# Defaults to `true`. This may need to be set to `false` when using a class
|
178
|
+
# autoloading system.
|
179
|
+
#
|
180
|
+
# @param policy [Boolean]
|
181
|
+
# @return [Boolean]
|
182
|
+
#
|
183
|
+
# @see add_to_load_path
|
184
|
+
# @see Container.configure
|
185
|
+
# @api public
|
186
|
+
#
|
187
|
+
# @!method add_to_load_path
|
188
|
+
#
|
189
|
+
# Returns the configured value.
|
190
|
+
#
|
191
|
+
# @return [Boolean]
|
192
|
+
#
|
193
|
+
# @see add_to_load_path=
|
194
|
+
# @api public
|
195
|
+
setting :add_to_load_path, default: true
|
196
|
+
|
153
197
|
# @api public
|
154
198
|
def default_namespace=(namespace)
|
155
199
|
Dry::Core::Deprecations.announce(
|
@@ -17,7 +17,7 @@ module Dry
|
|
17
17
|
#
|
18
18
|
# Sets a default `auto_register` for all added component dirs
|
19
19
|
#
|
20
|
-
# @see ComponentDir.auto_register
|
20
|
+
# @see ComponentDir.auto_register=
|
21
21
|
# @see auto_register
|
22
22
|
#
|
23
23
|
# @!method auto_register
|
@@ -26,24 +26,24 @@ module Dry
|
|
26
26
|
#
|
27
27
|
# @see auto_register=
|
28
28
|
|
29
|
-
# @!method
|
29
|
+
# @!method instance=(value)
|
30
30
|
#
|
31
|
-
# Sets a default `
|
31
|
+
# Sets a default `instance` for all added component dirs
|
32
32
|
#
|
33
|
-
# @see ComponentDir.
|
34
|
-
# @see
|
33
|
+
# @see ComponentDir.instance=
|
34
|
+
# @see auto_register
|
35
35
|
#
|
36
|
-
# @!method
|
36
|
+
# @!method auto_register
|
37
37
|
#
|
38
|
-
# Returns the configured default `
|
38
|
+
# Returns the configured default `instance`
|
39
39
|
#
|
40
|
-
# @see
|
40
|
+
# @see instance=
|
41
41
|
|
42
42
|
# @!method loader=(value)
|
43
43
|
#
|
44
44
|
# Sets a default `loader` value for all added component dirs
|
45
45
|
#
|
46
|
-
# @see ComponentDir.loader
|
46
|
+
# @see ComponentDir.loader=
|
47
47
|
# @see loader
|
48
48
|
#
|
49
49
|
# @!method loader
|
@@ -56,7 +56,7 @@ module Dry
|
|
56
56
|
#
|
57
57
|
# Sets a default `memoize` value for all added component dirs
|
58
58
|
#
|
59
|
-
# @see ComponentDir.memoize
|
59
|
+
# @see ComponentDir.memoize=
|
60
60
|
# @see memoize
|
61
61
|
#
|
62
62
|
# @!method memoize
|
@@ -77,6 +77,19 @@ module Dry
|
|
77
77
|
#
|
78
78
|
# @return [Namespaces] the namespaces
|
79
79
|
|
80
|
+
# @!method add_to_load_path=(value)
|
81
|
+
#
|
82
|
+
# Sets a default `add_to_load_path` value for all added component dirs
|
83
|
+
#
|
84
|
+
# @see ComponentDir.add_to_load_path=
|
85
|
+
# @see add_to_load_path
|
86
|
+
#
|
87
|
+
# @!method add_to_load_path
|
88
|
+
#
|
89
|
+
# Returns the configured default `add_to_load_path`
|
90
|
+
#
|
91
|
+
# @see add_to_load_path=
|
92
|
+
|
80
93
|
# rubocop:enable Layout/LineLength
|
81
94
|
|
82
95
|
# @!endgroup
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "dry/core/equalizer"
|
4
|
+
require "dry/system/constants"
|
4
5
|
|
5
6
|
module Dry
|
6
7
|
module System
|
@@ -54,7 +55,9 @@ module Dry
|
|
54
55
|
# @api private
|
55
56
|
def initialize(path:, key:, const:)
|
56
57
|
@path = path
|
57
|
-
|
58
|
+
# Default keys (i.e. when the user does not explicitly provide one) for non-root
|
59
|
+
# paths will include path separators, which we must convert into key separators
|
60
|
+
@key = key && key == path ? key.gsub(PATH_SEPARATOR, KEY_SEPARATOR) : key
|
58
61
|
@const = const
|
59
62
|
end
|
60
63
|
|
@@ -67,11 +70,6 @@ module Dry
|
|
67
70
|
def path?
|
68
71
|
!root?
|
69
72
|
end
|
70
|
-
|
71
|
-
# @api private
|
72
|
-
def default_key?
|
73
|
-
key == path
|
74
|
-
end
|
75
73
|
end
|
76
74
|
end
|
77
75
|
end
|