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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a2d2d74bfa80e0afcee1e54dd79e10a7c21548e0c634c99c2c7af17d97f34166
4
- data.tar.gz: 62b18ac8bd11c5b56b8637fa4a0bc90da69f61ac84a1b02d01e6b0739d2f166c
3
+ metadata.gz: 1142596b0e507d66a8d2fc50b0e547e562194002a66b560945b386007fee17ae
4
+ data.tar.gz: 01a300ee230fa9047f002d90c0a02fe8d80da49e56706deb2a29da67d2e1ea08
5
5
  SHA512:
6
- metadata.gz: b0f906601ede92930ad8c12621a5f68ea1ce6a8ce1e126c967632e51b4e79b8d20d49b682d273b6ca32ebdcd87d8201c3edcae007504ef74b5ac888dd4da0cb1
7
- data.tar.gz: 92fff5321a53a6e44644f82b56f1cf53a890c6c3b2ab4158bbb2caedbbd0538040165c650cb490e9d204bf585cf7121b61a8361cf895b588989b9e547cece0a4
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
@@ -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
@@ -8,10 +8,10 @@
8
8
  # dry-container [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
9
9
 
10
10
  [![Gem Version](https://badge.fury.io/rb/dry-container.svg)][gem]
11
- [![CI Status](https://github.com/dry-rb/dry-container/workflows/CI/badge.svg)][actions]
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=master)][inchpages]
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.6.0`
26
- * ~~jruby~~ `>= 9.3` (we are waiting for [2.6 support](https://github.com/jruby/jruby/issues/6161))
25
+ * MRI `>= 2.7.0`
26
+ * jruby `>= 9.3` (postponed until 2.7 is supported)
27
27
 
28
28
  ## License
29
29
 
@@ -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.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
- 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"
@@ -4,5 +4,10 @@ module Dry
4
4
  class Container
5
5
  # @api public
6
6
  Error = Class.new(StandardError)
7
+
8
+ KeyError = Class.new(::KeyError)
9
+ DidYouMean.correct_error(KeyError, DidYouMean::KeyErrorChecker)
10
+
11
+ deprecate_constant(:Error)
7
12
  end
8
13
  end
@@ -41,7 +41,7 @@ module Dry
41
41
 
42
42
  # @private
43
43
  def raise_not_supported_error
44
- raise ::Dry::Container::Error, "Memoize only supported for a block or a proc".freeze
44
+ raise ::Dry::Container::Error, "Memoize only supported for a block or a proc"
45
45
  end
46
46
  end
47
47
  end
@@ -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 ::Dry::Configurable
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 ::Dry::Configurable
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) do |a, h|
152
- h[PREFIX_NAMESPACE.call(namespace, a.first, config)] = a.last
153
- end
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 the registered item parameters.
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 over not just
204
- # the registered keys, but to see what was registered would be very helpful. This is a step
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
@@ -24,6 +24,7 @@ module Dry
24
24
  attr_reader :name
25
25
  # @return [Proc] The block to be executed when the namespace is imported
26
26
  attr_reader :block
27
+
27
28
  # Create a new namespace
28
29
  #
29
30
  # @param [Mixed] name
@@ -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 [Dry::Container::Error]
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 Error, "Nothing registered with the key #{key.inspect}"
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 the registered item parameters.
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 to iterate over not just
80
- # the registered keys, but to see what was registered would be very helpful. This is a step
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
@@ -3,6 +3,6 @@
3
3
  module Dry
4
4
  class Container
5
5
  # @api public
6
- VERSION = "0.9.0".freeze
6
+ VERSION = "0.10.0"
7
7
  end
8
8
  end
data/lib/dry/container.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry-configurable"
4
3
  require "dry/container/error"
5
4
  require "dry/container/namespace"
6
5
  require "dry/container/registry"
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.9.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: 2021-09-12 00:00:00.000000000 Z
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.6.0
110
+ version: 2.7.0
131
111
  required_rubygems_version: !ruby/object:Gem::Requirement
132
112
  requirements:
133
113
  - - ">="