dry-container 0.9.0 → 0.10.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/LICENSE +1 -1
- data/README.md +4 -4
- data/dry-container.gemspec +1 -2
- data/lib/dry/container/error.rb +5 -0
- data/lib/dry/container/item/memoizable.rb +1 -1
- data/lib/dry/container/mixin.rb +72 -20
- data/lib/dry/container/namespace.rb +1 -0
- data/lib/dry/container/resolver.rb +7 -6
- data/lib/dry/container/version.rb +1 -1
- data/lib/dry/container.rb +0 -1
- metadata +3 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1142596b0e507d66a8d2fc50b0e547e562194002a66b560945b386007fee17ae
|
4
|
+
data.tar.gz: 01a300ee230fa9047f002d90c0a02fe8d80da49e56706deb2a29da67d2e1ea08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7df2087f89345b9e5225f24226b7b20a2beceec88ebd424fa4a759808f7df1b355d2771370b4fbdc26d536891a68bd0c1f5b9353cb2301d10c80787466f59eaa
|
7
|
+
data.tar.gz: 3d83f9c597b41ad3b446ee0f1441ed42b443ac70ad0775bd17d8d5947fdf2508bf0f883e5f298ec16e908cd07bb7966f3688fba9ccd5606d76c400a76d0822c9
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
2
|
|
3
|
+
## 0.10.0 2022-07-10
|
4
|
+
|
5
|
+
⚠️ Notice that dry-container no longer depends on dry-configurable. If you happen to rely on the advanced configurable functionality, add dry-configurable as a dependency and require it **before** requiring dry-container.
|
6
|
+
|
7
|
+
### Added
|
8
|
+
|
9
|
+
- Accept block given to `#merge` (via #83) (@timriley)
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
|
13
|
+
- [BREAKING] Replace dep on dry-configurable with a simple `Configuration` mod (see #84 for more details) (@solnic)
|
14
|
+
- Raise KeyError for missing key, with DidYouMean integration (via #82) (@cllns)
|
15
|
+
- Wrap FrozenError, to state that the container itself is frozen (see #74) (@cllns)
|
16
|
+
|
17
|
+
[Compare v0.9.0...v0.10.0](https://github.com/dry-rb/dry-container/compare/v0.9.0...v0.10.0)
|
18
|
+
|
3
19
|
## 0.9.0 2021-09-12
|
4
20
|
|
5
21
|
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -8,10 +8,10 @@
|
|
8
8
|
# dry-container [][chat]
|
9
9
|
|
10
10
|
[][gem]
|
11
|
-
[][actions]
|
12
12
|
[][codacy]
|
13
13
|
[][codacy]
|
14
|
-
[][inchpages]
|
15
15
|
|
16
16
|
## Links
|
17
17
|
|
@@ -22,8 +22,8 @@
|
|
22
22
|
|
23
23
|
This library officially supports the following Ruby versions:
|
24
24
|
|
25
|
-
* MRI `>= 2.
|
26
|
-
*
|
25
|
+
* MRI `>= 2.7.0`
|
26
|
+
* jruby `>= 9.3` (postponed until 2.7 is supported)
|
27
27
|
|
28
28
|
## License
|
29
29
|
|
data/dry-container.gemspec
CHANGED
@@ -26,11 +26,10 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-container"
|
27
27
|
spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-container/issues"
|
28
28
|
|
29
|
-
spec.required_ruby_version = ">= 2.
|
29
|
+
spec.required_ruby_version = ">= 2.7.0"
|
30
30
|
|
31
31
|
# to update dependencies edit project.yml
|
32
32
|
spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
|
33
|
-
spec.add_runtime_dependency "dry-configurable", "~> 0.13", ">= 0.13.0"
|
34
33
|
|
35
34
|
spec.add_development_dependency "bundler"
|
36
35
|
spec.add_development_dependency "rake"
|
data/lib/dry/container/error.rb
CHANGED
data/lib/dry/container/mixin.rb
CHANGED
@@ -4,6 +4,61 @@ require "concurrent/hash"
|
|
4
4
|
|
5
5
|
module Dry
|
6
6
|
class Container
|
7
|
+
# @api public
|
8
|
+
class Config
|
9
|
+
DEFAULT_NAMESPACE_SEPARATOR = "."
|
10
|
+
DEFAULT_RESOLVER = Resolver.new
|
11
|
+
DEFAULT_REGISTRY = Registry.new
|
12
|
+
|
13
|
+
# @api public
|
14
|
+
attr_accessor :namespace_separator
|
15
|
+
|
16
|
+
# @api public
|
17
|
+
attr_accessor :resolver
|
18
|
+
|
19
|
+
# @api public
|
20
|
+
attr_accessor :registry
|
21
|
+
|
22
|
+
# @api private
|
23
|
+
def initialize(
|
24
|
+
namespace_separator: DEFAULT_NAMESPACE_SEPARATOR,
|
25
|
+
resolver: DEFAULT_RESOLVER,
|
26
|
+
registry: DEFAULT_REGISTRY
|
27
|
+
)
|
28
|
+
@namespace_separator = namespace_separator
|
29
|
+
@resolver = resolver
|
30
|
+
@registry = registry
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# @api public
|
35
|
+
module Configuration
|
36
|
+
# Use dry/configurable if it's available
|
37
|
+
if defined?(Configurable)
|
38
|
+
# @api private
|
39
|
+
def self.extended(klass)
|
40
|
+
super
|
41
|
+
klass.class_eval do
|
42
|
+
extend Dry::Configurable
|
43
|
+
|
44
|
+
setting :namespace_separator, default: Config::DEFAULT_NAMESPACE_SEPARATOR
|
45
|
+
setting :resolver, default: Config::DEFAULT_RESOLVER
|
46
|
+
setting :registry, default: Config::DEFAULT_REGISTRY
|
47
|
+
end
|
48
|
+
end
|
49
|
+
else
|
50
|
+
# @api private
|
51
|
+
def config
|
52
|
+
@config ||= Config.new
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# @api private
|
57
|
+
def configure
|
58
|
+
yield config
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
7
62
|
PREFIX_NAMESPACE = lambda do |namespace, key, config|
|
8
63
|
[namespace, key].join(config.namespace_separator)
|
9
64
|
end
|
@@ -31,7 +86,6 @@ module Dry
|
|
31
86
|
# container.resolve(:item)
|
32
87
|
# => 'item'
|
33
88
|
#
|
34
|
-
#
|
35
89
|
# @api public
|
36
90
|
module Mixin
|
37
91
|
# @private
|
@@ -44,13 +98,9 @@ module Dry
|
|
44
98
|
end
|
45
99
|
|
46
100
|
base.class_eval do
|
47
|
-
extend
|
101
|
+
extend Configuration
|
48
102
|
extend hooks_mod
|
49
103
|
|
50
|
-
setting :registry, default: Dry::Container::Registry.new
|
51
|
-
setting :resolver, default: Dry::Container::Resolver.new
|
52
|
-
setting :namespace_separator, default: "."
|
53
|
-
|
54
104
|
@_container = ::Concurrent::Hash.new
|
55
105
|
end
|
56
106
|
end
|
@@ -66,13 +116,9 @@ module Dry
|
|
66
116
|
# @private
|
67
117
|
def self.included(base)
|
68
118
|
base.class_eval do
|
69
|
-
extend
|
119
|
+
extend Configuration
|
70
120
|
prepend Initializer
|
71
121
|
|
72
|
-
setting :registry, default: Dry::Container::Registry.new
|
73
|
-
setting :resolver, default: Dry::Container::Resolver.new
|
74
|
-
setting :namespace_separator, default: "."
|
75
|
-
|
76
122
|
def config
|
77
123
|
self.class.config
|
78
124
|
end
|
@@ -105,6 +151,9 @@ module Dry
|
|
105
151
|
config.registry.call(_container, key, item, options)
|
106
152
|
|
107
153
|
self
|
154
|
+
rescue FrozenError
|
155
|
+
raise FrozenError,
|
156
|
+
"can't modify frozen #{self.class} (when attempting to register '#{key}')"
|
108
157
|
end
|
109
158
|
|
110
159
|
# Resolve an item from the container
|
@@ -145,15 +194,16 @@ module Dry
|
|
145
194
|
# @return [Dry::Container::Mixin] self
|
146
195
|
#
|
147
196
|
# @api public
|
148
|
-
def merge(other, namespace: nil)
|
197
|
+
def merge(other, namespace: nil, &block)
|
149
198
|
if namespace
|
150
199
|
_container.merge!(
|
151
|
-
other._container.each_with_object(::Concurrent::Hash.new)
|
152
|
-
|
153
|
-
|
200
|
+
other._container.each_with_object(::Concurrent::Hash.new) { |(key, item), hsh|
|
201
|
+
hsh[PREFIX_NAMESPACE.call(namespace, key, config)] = item
|
202
|
+
},
|
203
|
+
&block
|
154
204
|
)
|
155
205
|
else
|
156
|
-
_container.merge!(other._container)
|
206
|
+
_container.merge!(other._container, &block)
|
157
207
|
end
|
158
208
|
|
159
209
|
self
|
@@ -192,7 +242,8 @@ module Dry
|
|
192
242
|
self
|
193
243
|
end
|
194
244
|
|
195
|
-
# Calls block once for each key/value pair in the container, passing the key and
|
245
|
+
# Calls block once for each key/value pair in the container, passing the key and
|
246
|
+
# the registered item parameters.
|
196
247
|
#
|
197
248
|
# If no block is given, an enumerator is returned instead.
|
198
249
|
#
|
@@ -200,9 +251,9 @@ module Dry
|
|
200
251
|
#
|
201
252
|
# @api public
|
202
253
|
#
|
203
|
-
# @note In discussions with other developers, it was felt that being able to iterate
|
204
|
-
# the registered keys, but to see what was registered would be
|
205
|
-
# toward doing that.
|
254
|
+
# @note In discussions with other developers, it was felt that being able to iterate
|
255
|
+
# over not just the registered keys, but to see what was registered would be
|
256
|
+
# very helpful. This is a step toward doing that.
|
206
257
|
def each(&block)
|
207
258
|
config.resolver.each(_container, &block)
|
208
259
|
end
|
@@ -293,5 +344,6 @@ module Dry
|
|
293
344
|
copy
|
294
345
|
end
|
295
346
|
end
|
347
|
+
# rubocop: enable Metrics/ModuleLength
|
296
348
|
end
|
297
349
|
end
|
@@ -16,7 +16,7 @@ module Dry
|
|
16
16
|
# Fallback block to call when a key is missing. Its result will be returned
|
17
17
|
# @yieldparam [Mixed] key Missing key
|
18
18
|
#
|
19
|
-
# @raise [
|
19
|
+
# @raise [KeyError]
|
20
20
|
# If the given key is not registered with the container (and no block provided)
|
21
21
|
#
|
22
22
|
#
|
@@ -28,7 +28,7 @@ module Dry
|
|
28
28
|
if block_given?
|
29
29
|
return yield(key)
|
30
30
|
else
|
31
|
-
raise
|
31
|
+
raise KeyError.new(%(key not found: "#{key}"), key: key.to_s, receiver: container)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -69,16 +69,17 @@ module Dry
|
|
69
69
|
container.each_key(&block)
|
70
70
|
end
|
71
71
|
|
72
|
-
# Calls block once for each key in container, passing the key and
|
72
|
+
# Calls block once for each key in container, passing the key and
|
73
|
+
# the registered item parameters.
|
73
74
|
#
|
74
75
|
# If no block is given, an enumerator is returned instead.
|
75
76
|
#
|
76
77
|
# @return Key, Value
|
77
78
|
#
|
78
79
|
# @api public
|
79
|
-
# @note In discussions with other developers, it was felt that being able
|
80
|
-
# the registered keys, but to see what was
|
81
|
-
# toward doing that.
|
80
|
+
# @note In discussions with other developers, it was felt that being able
|
81
|
+
# to iterate over not just the registered keys, but to see what was
|
82
|
+
# registered would be very helpful. This is a step toward doing that.
|
82
83
|
def each(container, &block)
|
83
84
|
container.map { |key, value| [key, value.call] }.each(&block)
|
84
85
|
end
|
data/lib/dry/container.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-container
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Holland
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -24,26 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: dry-configurable
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0.13'
|
34
|
-
- - ">="
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: 0.13.0
|
37
|
-
type: :runtime
|
38
|
-
prerelease: false
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
40
|
-
requirements:
|
41
|
-
- - "~>"
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '0.13'
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 0.13.0
|
47
27
|
- !ruby/object:Gem::Dependency
|
48
28
|
name: bundler
|
49
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -127,7 +107,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
127
107
|
requirements:
|
128
108
|
- - ">="
|
129
109
|
- !ruby/object:Gem::Version
|
130
|
-
version: 2.
|
110
|
+
version: 2.7.0
|
131
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
112
|
requirements:
|
133
113
|
- - ">="
|