dry-container 0.8.0 → 0.11.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 +52 -0
- data/LICENSE +1 -1
- data/README.md +3 -3
- data/dry-container.gemspec +1 -6
- data/lib/dry/container/error.rb +7 -0
- data/lib/dry/container/item/memoizable.rb +1 -1
- data/lib/dry/container/mixin.rb +76 -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: eddc5e64785c83df02d42faf679ab88dac5ff2c274540cc28ebc9d1b222adda1
|
4
|
+
data.tar.gz: fc6a1ed68bb2cb5f59d8f16c6bf14574cdac67d4d41ffc9ebfbfb5f49b7ba1a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f42fd1605859002fe9edc2f1a1cdda1cf76977e50d49e4e6808a4e99e94e2191fc771ab085d30480fc20678045b84733ab35caab90b0c5591e71639c8f2e644
|
7
|
+
data.tar.gz: 266cc28987cbbf03b606514175ac8ee42f2565686594b3ae94e72f2484b107a49ba455153bdc12c83849ae53ff80225c6e387c6894ff5c4cb2d665b496275533
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,57 @@
|
|
1
1
|
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
2
|
|
3
|
+
## 0.11.0 2022-09-16
|
4
|
+
|
5
|
+
|
6
|
+
### Changed
|
7
|
+
|
8
|
+
- dry-configurable will be used whenever it is in the $LOAD_PATH (see dry-rb/dry-system#247 for more context) (@solnic)
|
9
|
+
|
10
|
+
[Compare v0.10.1...v0.11.0](https://github.com/dry-rb/dry-container/compare/v0.10.1...v0.11.0)
|
11
|
+
|
12
|
+
## 0.10.1 2022-07-29
|
13
|
+
|
14
|
+
|
15
|
+
### Changed
|
16
|
+
|
17
|
+
- Make `DidYouMean` integration optional (via #86) (@jbourassa)
|
18
|
+
|
19
|
+
[Compare v0.10.0...v0.10.1](https://github.com/dry-rb/dry-container/compare/v0.10.0...v0.10.1)
|
20
|
+
|
21
|
+
## 0.10.0 2022-07-10
|
22
|
+
|
23
|
+
⚠️ 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.
|
24
|
+
|
25
|
+
### Added
|
26
|
+
|
27
|
+
- Accept block given to `#merge` (via #83) (@timriley)
|
28
|
+
|
29
|
+
### Changed
|
30
|
+
|
31
|
+
- [BREAKING] Replace dep on dry-configurable with a simple `Configuration` mod (see #84 for more details) (@solnic)
|
32
|
+
- Raise KeyError for missing key, with DidYouMean integration (via #82) (@cllns)
|
33
|
+
- Wrap FrozenError, to state that the container itself is frozen (see #74) (@cllns)
|
34
|
+
|
35
|
+
[Compare v0.9.0...v0.10.0](https://github.com/dry-rb/dry-container/compare/v0.9.0...v0.10.0)
|
36
|
+
|
37
|
+
## 0.9.0 2021-09-12
|
38
|
+
|
39
|
+
|
40
|
+
### Changed
|
41
|
+
|
42
|
+
- [internal] Upgraded to new `setting` API provided in dry-configurable 0.13.0 (@timriley in #77)
|
43
|
+
|
44
|
+
[Compare v0.8.0...v0.9.0](https://github.com/dry-rb/dry-container/compare/v0.8.0...v0.9.0)
|
45
|
+
|
46
|
+
## 0.8.0 2021-06-06
|
47
|
+
|
48
|
+
|
49
|
+
### Changed
|
50
|
+
|
51
|
+
- [BREAKING] Support for 2.4 and 2.5 was dropped
|
52
|
+
|
53
|
+
[Compare v0.7.2...v0.8.0](https://github.com/dry-rb/dry-container/compare/v0.7.2...v0.8.0)
|
54
|
+
|
3
55
|
## 0.7.2 2019-07-09
|
4
56
|
|
5
57
|
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
[![CI Status](https://github.com/dry-rb/dry-container/workflows/ci/badge.svg)][actions]
|
12
12
|
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/227509c9034340b493f769f6277f4ecb)][codacy]
|
13
13
|
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/227509c9034340b493f769f6277f4ecb)][codacy]
|
14
|
-
[![Inline docs](http://inch-ci.org/github/dry-rb/dry-container.svg?branch=
|
14
|
+
[![Inline docs](http://inch-ci.org/github/dry-rb/dry-container.svg?branch=main)][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
|
-
* jruby `>= 9.2
|
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,15 +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
|
-
|
30
|
-
spec.required_ruby_version = ">= 2.5.0"
|
31
|
-
else
|
32
|
-
spec.required_ruby_version = ">= 2.6.0"
|
33
|
-
end
|
29
|
+
spec.required_ruby_version = ">= 2.7.0"
|
34
30
|
|
35
31
|
# to update dependencies edit project.yml
|
36
32
|
spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
|
37
|
-
spec.add_runtime_dependency "dry-configurable", "~> 0.1", ">= 0.1.3"
|
38
33
|
|
39
34
|
spec.add_development_dependency "bundler"
|
40
35
|
spec.add_development_dependency "rake"
|
data/lib/dry/container/error.rb
CHANGED
@@ -4,5 +4,12 @@ module Dry
|
|
4
4
|
class Container
|
5
5
|
# @api public
|
6
6
|
Error = Class.new(StandardError)
|
7
|
+
|
8
|
+
KeyError = Class.new(::KeyError)
|
9
|
+
if defined?(DidYouMean::KeyErrorChecker)
|
10
|
+
DidYouMean.correct_error(KeyError, DidYouMean::KeyErrorChecker)
|
11
|
+
end
|
12
|
+
|
13
|
+
deprecate_constant(:Error)
|
7
14
|
end
|
8
15
|
end
|
data/lib/dry/container/mixin.rb
CHANGED
@@ -4,6 +4,63 @@ 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
|
+
begin
|
38
|
+
require "dry/configurable"
|
39
|
+
|
40
|
+
# @api private
|
41
|
+
def self.extended(klass)
|
42
|
+
super
|
43
|
+
klass.class_eval do
|
44
|
+
extend Dry::Configurable
|
45
|
+
|
46
|
+
setting :namespace_separator, default: Config::DEFAULT_NAMESPACE_SEPARATOR
|
47
|
+
setting :resolver, default: Config::DEFAULT_RESOLVER
|
48
|
+
setting :registry, default: Config::DEFAULT_REGISTRY
|
49
|
+
end
|
50
|
+
end
|
51
|
+
rescue LoadError
|
52
|
+
# @api private
|
53
|
+
def config
|
54
|
+
@config ||= Config.new
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# @api private
|
59
|
+
def configure
|
60
|
+
yield config
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
7
64
|
PREFIX_NAMESPACE = lambda do |namespace, key, config|
|
8
65
|
[namespace, key].join(config.namespace_separator)
|
9
66
|
end
|
@@ -31,8 +88,9 @@ module Dry
|
|
31
88
|
# container.resolve(:item)
|
32
89
|
# => 'item'
|
33
90
|
#
|
34
|
-
#
|
35
91
|
# @api public
|
92
|
+
#
|
93
|
+
# rubocop:disable Metrics/ModuleLength
|
36
94
|
module Mixin
|
37
95
|
# @private
|
38
96
|
def self.extended(base)
|
@@ -44,13 +102,9 @@ module Dry
|
|
44
102
|
end
|
45
103
|
|
46
104
|
base.class_eval do
|
47
|
-
extend
|
105
|
+
extend Configuration
|
48
106
|
extend hooks_mod
|
49
107
|
|
50
|
-
setting :registry, ::Dry::Container::Registry.new
|
51
|
-
setting :resolver, ::Dry::Container::Resolver.new
|
52
|
-
setting :namespace_separator, "."
|
53
|
-
|
54
108
|
@_container = ::Concurrent::Hash.new
|
55
109
|
end
|
56
110
|
end
|
@@ -66,13 +120,9 @@ module Dry
|
|
66
120
|
# @private
|
67
121
|
def self.included(base)
|
68
122
|
base.class_eval do
|
69
|
-
extend
|
123
|
+
extend Configuration
|
70
124
|
prepend Initializer
|
71
125
|
|
72
|
-
setting :registry, ::Dry::Container::Registry.new
|
73
|
-
setting :resolver, ::Dry::Container::Resolver.new
|
74
|
-
setting :namespace_separator, "."
|
75
|
-
|
76
126
|
def config
|
77
127
|
self.class.config
|
78
128
|
end
|
@@ -105,6 +155,9 @@ module Dry
|
|
105
155
|
config.registry.call(_container, key, item, options)
|
106
156
|
|
107
157
|
self
|
158
|
+
rescue FrozenError
|
159
|
+
raise FrozenError,
|
160
|
+
"can't modify frozen #{self.class} (when attempting to register '#{key}')"
|
108
161
|
end
|
109
162
|
|
110
163
|
# Resolve an item from the container
|
@@ -145,15 +198,16 @@ module Dry
|
|
145
198
|
# @return [Dry::Container::Mixin] self
|
146
199
|
#
|
147
200
|
# @api public
|
148
|
-
def merge(other, namespace: nil)
|
201
|
+
def merge(other, namespace: nil, &block)
|
149
202
|
if namespace
|
150
203
|
_container.merge!(
|
151
|
-
other._container.each_with_object(::Concurrent::Hash.new)
|
152
|
-
|
153
|
-
|
204
|
+
other._container.each_with_object(::Concurrent::Hash.new) { |(key, item), hsh|
|
205
|
+
hsh[PREFIX_NAMESPACE.call(namespace, key, config)] = item
|
206
|
+
},
|
207
|
+
&block
|
154
208
|
)
|
155
209
|
else
|
156
|
-
_container.merge!(other._container)
|
210
|
+
_container.merge!(other._container, &block)
|
157
211
|
end
|
158
212
|
|
159
213
|
self
|
@@ -192,7 +246,8 @@ module Dry
|
|
192
246
|
self
|
193
247
|
end
|
194
248
|
|
195
|
-
# Calls block once for each key/value pair in the container, passing the key and
|
249
|
+
# Calls block once for each key/value pair in the container, passing the key and
|
250
|
+
# the registered item parameters.
|
196
251
|
#
|
197
252
|
# If no block is given, an enumerator is returned instead.
|
198
253
|
#
|
@@ -200,9 +255,9 @@ module Dry
|
|
200
255
|
#
|
201
256
|
# @api public
|
202
257
|
#
|
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.
|
258
|
+
# @note In discussions with other developers, it was felt that being able to iterate
|
259
|
+
# over not just the registered keys, but to see what was registered would be
|
260
|
+
# very helpful. This is a step toward doing that.
|
206
261
|
def each(&block)
|
207
262
|
config.resolver.each(_container, &block)
|
208
263
|
end
|
@@ -293,5 +348,6 @@ module Dry
|
|
293
348
|
copy
|
294
349
|
end
|
295
350
|
end
|
351
|
+
# rubocop:enable Metrics/ModuleLength
|
296
352
|
end
|
297
353
|
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.11.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-09-16 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.1'
|
34
|
-
- - ">="
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: 0.1.3
|
37
|
-
type: :runtime
|
38
|
-
prerelease: false
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
40
|
-
requirements:
|
41
|
-
- - "~>"
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '0.1'
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 0.1.3
|
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
|
- - ">="
|