dry-system 1.0.0 → 1.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +33 -0
- data/LICENSE +1 -1
- data/README.md +5 -12
- data/dry-system.gemspec +5 -5
- data/lib/dry/system/constants.rb +1 -1
- data/lib/dry/system/container.rb +3 -3
- data/lib/dry/system/loader.rb +1 -1
- data/lib/dry/system/magic_comments_parser.rb +2 -2
- data/lib/dry/system/plugins/monitoring.rb +1 -1
- data/lib/dry/system/provider_registrar.rb +35 -35
- data/lib/dry/system/provider_source_registry.rb +19 -8
- data/lib/dry/system/provider_sources.rb +1 -0
- data/lib/dry/system/version.rb +1 -1
- data/lib/dry/system.rb +13 -3
- metadata +8 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0772f1a642fb7e44cdafda2659b417fec6f8d583c14098751a94d1163c9c5571
|
4
|
+
data.tar.gz: 37a2e8c32bff3b24b1ff47f7bdb5095057dc5d7283327a3eab7c1424964c9f08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb137a83e1fa1eba5578255c6535282edfee7608faf4dbe9771d4dfda4cafbeeef167bb970c986b86e5a1e34162275ca63d796bf1d53148148df2dc835f2db80
|
7
|
+
data.tar.gz: 42c3050148a8de2e63376642ca4be35f6726b8462d708935ecb206d353ff0f6bf3b45a47e38b8440c368a88592933973705756de81cfd5be7066e0b41ff6d785
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,38 @@
|
|
1
1
|
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
2
|
|
3
|
+
## 1.1.0.beta1 2024-07-03
|
4
|
+
|
5
|
+
|
6
|
+
### Added
|
7
|
+
|
8
|
+
- Add `Dry::System::ProviderRegistrar#target_container`, to be passed when initializing
|
9
|
+
providers. By default this is an alias of `#container`. This allows for custom provider
|
10
|
+
registrars to override `#target_container` to provide a custom `#target` within providers.
|
11
|
+
An overridden value **MUST** still wrap the original `#target_container` to ensure components
|
12
|
+
are registered in the right place. (via #270) (@timriley)
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
|
16
|
+
- Make `Dry::System::ProviderRegistrar` public API (via #270) (@timriley)
|
17
|
+
- When registering a provider source, you can now provide a `provider_options:` hash of default
|
18
|
+
options for providers to be registered using that source. The one provider option currently
|
19
|
+
supported is `namespace:`. (via #271) (@timriley)
|
20
|
+
- Load providers when accessing them via `Dry::System::ProviderRegistrar#[]`. The previous,
|
21
|
+
behavior of `#[]` returning `nil` if a provider had not been explicitly loaded was a
|
22
|
+
potential source of confusion. Now `#[]` can serve as the one and only interface for fetching
|
23
|
+
a provider. (via #273) (@timriley)
|
24
|
+
|
25
|
+
[Compare v1.0.1...v1.1.0.beta1](https://github.com/dry-rb/dry-system/compare/v1.0.1...v1.1.0.beta1)
|
26
|
+
|
27
|
+
## 1.0.1 2022-11-18
|
28
|
+
|
29
|
+
|
30
|
+
### Changed
|
31
|
+
|
32
|
+
- Bumped dry-auto_inject dependency to its 1.0.0 final release (@solnic)
|
33
|
+
|
34
|
+
[Compare v1.0.0...v1.0.1](https://github.com/dry-rb/dry-system/compare/v1.0.0...v1.0.1)
|
35
|
+
|
3
36
|
## 1.0.0 2022-11-18
|
4
37
|
|
5
38
|
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,29 +1,22 @@
|
|
1
1
|
<!--- this file is synced from dry-rb/template-gem project -->
|
2
|
+
|
2
3
|
[gem]: https://rubygems.org/gems/dry-system
|
3
4
|
[actions]: https://github.com/dry-rb/dry-system/actions
|
4
|
-
[codacy]: https://www.codacy.com/gh/dry-rb/dry-system
|
5
|
-
[chat]: https://dry-rb.zulipchat.com
|
6
|
-
[inchpages]: http://inch-ci.org/github/dry-rb/dry-system
|
7
|
-
|
8
|
-
# dry-system [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
|
9
5
|
|
10
|
-
[![Gem Version](https://badge.fury.io/rb/dry-system.svg)][gem]
|
11
|
-
[![CI Status](https://github.com/dry-rb/dry-system/workflows/ci/badge.svg)][actions]
|
12
|
-
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/3a0e30d0ae2542c7ba047ba5f923c0bb)][codacy]
|
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=main)][inchpages]
|
6
|
+
# dry-system [![Gem Version](https://badge.fury.io/rb/dry-system.svg)][gem] [![CI Status](https://github.com/dry-rb/dry-system/workflows/CI/badge.svg)][actions]
|
15
7
|
|
16
8
|
## Links
|
17
9
|
|
18
10
|
* [User documentation](https://dry-rb.org/gems/dry-system)
|
19
11
|
* [API documentation](http://rubydoc.info/gems/dry-system)
|
12
|
+
* [Forum](https://discourse.dry-rb.org)
|
20
13
|
|
21
14
|
## Supported Ruby versions
|
22
15
|
|
23
16
|
This library officially supports the following Ruby versions:
|
24
17
|
|
25
|
-
* MRI `>=
|
26
|
-
* jruby `>= 9.
|
18
|
+
* MRI `>= 3.0`
|
19
|
+
* jruby `>= 9.4` (not tested on CI)
|
27
20
|
|
28
21
|
## License
|
29
22
|
|
data/dry-system.gemspec
CHANGED
@@ -26,13 +26,13 @@ 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 = ">=
|
29
|
+
spec.required_ruby_version = ">= 3.0"
|
30
30
|
|
31
31
|
# to update dependencies edit project.yml
|
32
|
-
spec.add_runtime_dependency "dry-auto_inject", "~> 1.0
|
33
|
-
spec.add_runtime_dependency "dry-configurable", "~> 1.0"
|
34
|
-
spec.add_runtime_dependency "dry-core", "~> 1.0"
|
35
|
-
spec.add_runtime_dependency "dry-inflector", "~> 1.0"
|
32
|
+
spec.add_runtime_dependency "dry-auto_inject", "~> 1.0"
|
33
|
+
spec.add_runtime_dependency "dry-configurable", "~> 1.0"
|
34
|
+
spec.add_runtime_dependency "dry-core", "~> 1.0"
|
35
|
+
spec.add_runtime_dependency "dry-inflector", "~> 1.0"
|
36
36
|
|
37
37
|
spec.add_development_dependency "bundler"
|
38
38
|
spec.add_development_dependency "rake"
|
data/lib/dry/system/constants.rb
CHANGED
data/lib/dry/system/container.rb
CHANGED
@@ -148,7 +148,7 @@ module Dry
|
|
148
148
|
#
|
149
149
|
# @example
|
150
150
|
# # system/container.rb
|
151
|
-
# require "dry/system
|
151
|
+
# require "dry/system"
|
152
152
|
# require "logger"
|
153
153
|
#
|
154
154
|
# class Core < Dry::System::Container
|
@@ -608,14 +608,14 @@ module Dry
|
|
608
608
|
def load_component(key)
|
609
609
|
return self if registered?(key)
|
610
610
|
|
611
|
-
if (provider = providers
|
611
|
+
if (provider = providers[key])
|
612
612
|
provider.start
|
613
613
|
return self
|
614
614
|
end
|
615
615
|
|
616
616
|
component = find_component(key)
|
617
617
|
|
618
|
-
providers.
|
618
|
+
providers[component.root_key]&.start
|
619
619
|
return self if registered?(key)
|
620
620
|
|
621
621
|
if component.loadable?
|
data/lib/dry/system/loader.rb
CHANGED
@@ -67,7 +67,7 @@ module Dry
|
|
67
67
|
inflector.constantize(const_name)
|
68
68
|
rescue NameError => e
|
69
69
|
# Ensure it's this component's constant, not any other NameError within the component
|
70
|
-
if e.message =~ /#{const_name}( |\n)/
|
70
|
+
if e.message =~ /#{const_name}( |\n|$)/
|
71
71
|
raise ComponentNotLoadableError.new(component, e)
|
72
72
|
else
|
73
73
|
raise e
|
@@ -3,8 +3,8 @@
|
|
3
3
|
module Dry
|
4
4
|
module System
|
5
5
|
class MagicCommentsParser
|
6
|
-
VALID_LINE_RE = /^(#.*)
|
7
|
-
COMMENT_RE = /^#\s+(?<name>[A-Za-z]{1}[A-Za-z0-9_]+):\s+(?<value>.+?)
|
6
|
+
VALID_LINE_RE = /^(#.*)?$/
|
7
|
+
COMMENT_RE = /^#\s+(?<name>[A-Za-z]{1}[A-Za-z0-9_]+):\s+(?<value>.+?)$/
|
8
8
|
|
9
9
|
COERCIONS = {
|
10
10
|
"true" => true,
|
@@ -13,7 +13,8 @@ module Dry
|
|
13
13
|
# provider registrar is responsible for loading provider files and exposing an API for
|
14
14
|
# running the provider lifecycle steps.
|
15
15
|
#
|
16
|
-
# @api
|
16
|
+
# @api public
|
17
|
+
# @since 1.1.0
|
17
18
|
class ProviderRegistrar
|
18
19
|
# @api private
|
19
20
|
attr_reader :providers
|
@@ -21,6 +22,14 @@ module Dry
|
|
21
22
|
# @api private
|
22
23
|
attr_reader :container
|
23
24
|
|
25
|
+
# Returns the container exposed to providers as `target_container`.
|
26
|
+
#
|
27
|
+
# @return [Dry::System::Container]
|
28
|
+
#
|
29
|
+
# @api public
|
30
|
+
# @since 1.1.0
|
31
|
+
alias_method :target_container, :container
|
32
|
+
|
24
33
|
# @api private
|
25
34
|
def initialize(container)
|
26
35
|
@providers = {}
|
@@ -37,7 +46,7 @@ module Dry
|
|
37
46
|
|
38
47
|
# @see Container.register_provider
|
39
48
|
# @api private
|
40
|
-
def register_provider(name,
|
49
|
+
def register_provider(name, from: nil, source: nil, if: true, **provider_options, &block)
|
41
50
|
raise ProviderAlreadyRegisteredError, name if providers.key?(name)
|
42
51
|
|
43
52
|
if from && source.is_a?(Class)
|
@@ -54,13 +63,18 @@ module Dry
|
|
54
63
|
if from
|
55
64
|
build_provider_from_source(
|
56
65
|
name,
|
57
|
-
namespace: namespace,
|
58
66
|
source: source || name,
|
59
67
|
group: from,
|
68
|
+
options: provider_options,
|
60
69
|
&block
|
61
70
|
)
|
62
71
|
else
|
63
|
-
build_provider(
|
72
|
+
build_provider(
|
73
|
+
name,
|
74
|
+
source: source,
|
75
|
+
options: provider_options,
|
76
|
+
&block
|
77
|
+
)
|
64
78
|
end
|
65
79
|
|
66
80
|
providers[provider.name] = provider
|
@@ -70,43 +84,28 @@ module Dry
|
|
70
84
|
|
71
85
|
# rubocop:enable Metrics/PerceivedComplexity
|
72
86
|
|
73
|
-
# Returns a provider for the given name, if it has already been loaded
|
74
|
-
#
|
75
|
-
# @api public
|
76
|
-
def [](provider_name)
|
77
|
-
providers[provider_name]
|
78
|
-
end
|
79
|
-
alias_method :provider, :[]
|
80
|
-
|
81
|
-
# @api private
|
82
|
-
def key?(provider_name)
|
83
|
-
providers.key?(provider_name)
|
84
|
-
end
|
85
|
-
|
86
87
|
# Returns a provider if it can be found or loaded, otherwise nil
|
87
88
|
#
|
88
89
|
# @return [Dry::System::Provider, nil]
|
89
90
|
#
|
90
|
-
# @api
|
91
|
-
def
|
92
|
-
|
91
|
+
# @api public
|
92
|
+
def [](provider_name)
|
93
|
+
provider_name = provider_name.to_sym
|
93
94
|
|
94
|
-
if (provider = providers[
|
95
|
+
if (provider = providers[provider_name])
|
95
96
|
return provider
|
96
97
|
end
|
97
98
|
|
98
99
|
return if finalized?
|
99
100
|
|
100
|
-
require_provider_file(
|
101
|
+
require_provider_file(provider_name)
|
101
102
|
|
102
|
-
providers[
|
103
|
+
providers[provider_name]
|
103
104
|
end
|
104
105
|
|
105
106
|
# @api private
|
106
|
-
def
|
107
|
-
|
108
|
-
provider.start
|
109
|
-
end
|
107
|
+
def key?(provider_name)
|
108
|
+
providers.key?(provider_name)
|
110
109
|
end
|
111
110
|
|
112
111
|
# Returns all provider files within the configured provider_paths.
|
@@ -196,25 +195,26 @@ module Dry
|
|
196
195
|
}
|
197
196
|
end
|
198
197
|
|
199
|
-
def build_provider(name,
|
198
|
+
def build_provider(name, options:, source: nil, &block)
|
200
199
|
source_class = source || Provider::Source.for(name: name, &block)
|
201
200
|
|
202
201
|
Provider.new(
|
202
|
+
**options,
|
203
203
|
name: name,
|
204
|
-
|
205
|
-
target_container: container,
|
204
|
+
target_container: target_container,
|
206
205
|
source_class: source_class
|
207
206
|
)
|
208
207
|
end
|
209
208
|
|
210
|
-
def build_provider_from_source(name, source:, group:,
|
211
|
-
|
209
|
+
def build_provider_from_source(name, source:, group:, options:, &block)
|
210
|
+
provider_source = System.provider_sources.resolve(name: source, group: group)
|
212
211
|
|
213
212
|
Provider.new(
|
213
|
+
**provider_source.provider_options,
|
214
|
+
**options,
|
214
215
|
name: name,
|
215
|
-
|
216
|
-
|
217
|
-
source_class: source_class,
|
216
|
+
target_container: target_container,
|
217
|
+
source_class: provider_source.source,
|
218
218
|
&block
|
219
219
|
)
|
220
220
|
end
|
@@ -6,6 +6,17 @@ module Dry
|
|
6
6
|
module System
|
7
7
|
# @api private
|
8
8
|
class ProviderSourceRegistry
|
9
|
+
# @api private
|
10
|
+
class Registration
|
11
|
+
attr_reader :source
|
12
|
+
attr_reader :provider_options
|
13
|
+
|
14
|
+
def initialize(source:, provider_options:)
|
15
|
+
@source = source
|
16
|
+
@provider_options = provider_options
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
9
20
|
attr_reader :sources
|
10
21
|
|
11
22
|
def initialize
|
@@ -18,19 +29,19 @@ module Dry
|
|
18
29
|
end
|
19
30
|
end
|
20
31
|
|
21
|
-
def register(name:, group:, source:)
|
22
|
-
sources[key(name, group)] =
|
32
|
+
def register(name:, group:, source:, provider_options:)
|
33
|
+
sources[key(name, group)] = Registration.new(
|
34
|
+
source: source,
|
35
|
+
provider_options: provider_options
|
36
|
+
)
|
23
37
|
end
|
24
38
|
|
25
|
-
def register_from_block(name:, group:, &block)
|
39
|
+
def register_from_block(name:, group:, provider_options:, &block)
|
26
40
|
register(
|
27
41
|
name: name,
|
28
42
|
group: group,
|
29
|
-
source: Provider::Source.for(
|
30
|
-
|
31
|
-
group: group,
|
32
|
-
&block
|
33
|
-
)
|
43
|
+
source: Provider::Source.for(name: name, group: group, &block),
|
44
|
+
provider_options: provider_options
|
34
45
|
)
|
35
46
|
end
|
36
47
|
|
data/lib/dry/system/version.rb
CHANGED
data/lib/dry/system.rb
CHANGED
@@ -30,15 +30,25 @@ module Dry
|
|
30
30
|
# Registers a provider source, which can be used as the basis for other providers
|
31
31
|
#
|
32
32
|
# @api public
|
33
|
-
def self.register_provider_source(name, group:, source: nil, &block)
|
33
|
+
def self.register_provider_source(name, group:, source: nil, provider_options: {}, &block)
|
34
34
|
if source && block
|
35
35
|
raise ArgumentError, "You must supply only a `source:` option or a block, not both"
|
36
36
|
end
|
37
37
|
|
38
38
|
if source
|
39
|
-
provider_sources.register(
|
39
|
+
provider_sources.register(
|
40
|
+
name: name,
|
41
|
+
group: group,
|
42
|
+
source: source,
|
43
|
+
provider_options: provider_options
|
44
|
+
)
|
40
45
|
else
|
41
|
-
provider_sources.register_from_block(
|
46
|
+
provider_sources.register_from_block(
|
47
|
+
name: name,
|
48
|
+
group: group,
|
49
|
+
provider_options: provider_options,
|
50
|
+
&block
|
51
|
+
)
|
42
52
|
end
|
43
53
|
end
|
44
54
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-system
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.1.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-auto_inject
|
@@ -16,20 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.0
|
20
|
-
- - "<"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '2'
|
19
|
+
version: '1.0'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: 1.0
|
30
|
-
- - "<"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '2'
|
26
|
+
version: '1.0'
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: dry-configurable
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -37,9 +31,6 @@ dependencies:
|
|
37
31
|
- - "~>"
|
38
32
|
- !ruby/object:Gem::Version
|
39
33
|
version: '1.0'
|
40
|
-
- - "<"
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: '2'
|
43
34
|
type: :runtime
|
44
35
|
prerelease: false
|
45
36
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -47,9 +38,6 @@ dependencies:
|
|
47
38
|
- - "~>"
|
48
39
|
- !ruby/object:Gem::Version
|
49
40
|
version: '1.0'
|
50
|
-
- - "<"
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: '2'
|
53
41
|
- !ruby/object:Gem::Dependency
|
54
42
|
name: dry-core
|
55
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -57,9 +45,6 @@ dependencies:
|
|
57
45
|
- - "~>"
|
58
46
|
- !ruby/object:Gem::Version
|
59
47
|
version: '1.0'
|
60
|
-
- - "<"
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: '2'
|
63
48
|
type: :runtime
|
64
49
|
prerelease: false
|
65
50
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -67,9 +52,6 @@ dependencies:
|
|
67
52
|
- - "~>"
|
68
53
|
- !ruby/object:Gem::Version
|
69
54
|
version: '1.0'
|
70
|
-
- - "<"
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
version: '2'
|
73
55
|
- !ruby/object:Gem::Dependency
|
74
56
|
name: dry-inflector
|
75
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -77,9 +59,6 @@ dependencies:
|
|
77
59
|
- - "~>"
|
78
60
|
- !ruby/object:Gem::Version
|
79
61
|
version: '1.0'
|
80
|
-
- - "<"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '2'
|
83
62
|
type: :runtime
|
84
63
|
prerelease: false
|
85
64
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -87,9 +66,6 @@ dependencies:
|
|
87
66
|
- - "~>"
|
88
67
|
- !ruby/object:Gem::Version
|
89
68
|
version: '1.0'
|
90
|
-
- - "<"
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
version: '2'
|
93
69
|
- !ruby/object:Gem::Dependency
|
94
70
|
name: bundler
|
95
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -201,14 +177,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
201
177
|
requirements:
|
202
178
|
- - ">="
|
203
179
|
- !ruby/object:Gem::Version
|
204
|
-
version:
|
180
|
+
version: '3.0'
|
205
181
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
206
182
|
requirements:
|
207
|
-
- - "
|
183
|
+
- - ">"
|
208
184
|
- !ruby/object:Gem::Version
|
209
|
-
version:
|
185
|
+
version: 1.3.1
|
210
186
|
requirements: []
|
211
|
-
rubygems_version: 3.
|
187
|
+
rubygems_version: 3.3.27
|
212
188
|
signing_key:
|
213
189
|
specification_version: 4
|
214
190
|
summary: Organize your code into reusable components
|