dry-container 0.7.2 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac1a656d67e37d72da3265e2f092e507460cba4615db8f3727ee1acbca41584c
4
- data.tar.gz: be191bd45d43147d12c858d8683463be5e59a66ef2f473e8c19d7010bda0794c
3
+ metadata.gz: eddc5e64785c83df02d42faf679ab88dac5ff2c274540cc28ebc9d1b222adda1
4
+ data.tar.gz: fc6a1ed68bb2cb5f59d8f16c6bf14574cdac67d4d41ffc9ebfbfb5f49b7ba1a4
5
5
  SHA512:
6
- metadata.gz: c95deccc6ad3f976d31949d1a39e1bc4d6f5797604045aed3f7254d3a1e88ca35c76ee0483ad14bbc6abe0aed8fb13d157cd793c6eb1ff417343a0037a56358f
7
- data.tar.gz: a6bac7cb3f1819b6bb89a2989de1fe0c3d9a182144a556394cec1f8a1d48bf848589c57ffc7b4daaac106cb0a5673b086f901f2b1deba81c64796a6a1038c6c0
6
+ metadata.gz: 3f42fd1605859002fe9edc2f1a1cdda1cf76977e50d49e4e6808a4e99e94e2191fc771ab085d30480fc20678045b84733ab35caab90b0c5591e71639c8f2e644
7
+ data.tar.gz: 266cc28987cbbf03b606514175ac8ee42f2565686594b3ae94e72f2484b107a49ba455153bdc12c83849ae53ff80225c6e387c6894ff5c4cb2d665b496275533
data/CHANGELOG.md CHANGED
@@ -1,49 +1,93 @@
1
- ## v0.7.2 - 2019-07-09
1
+ <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
2
 
3
- ## Added
3
+ ## 0.11.0 2022-09-16
4
4
 
5
- * `.resolve` accepts an optional fallback block, similar to how `Hash#fetch` works ([flash-gordon](https://github.com/flash-gordon))
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
+
55
+ ## 0.7.2 2019-07-09
56
+
57
+
58
+ ### Added
59
+
60
+ - `.resolve` accepts an optional fallback block, similar to how `Hash#fetch` works ([flash-gordon](https://github.com/flash-gordon))
6
61
  ```ruby
7
62
  container.resolve('missing_key') { :fallback } # => :fallback
8
63
  ```
9
- * `.decorate` can (again) work with static values. Also, it can take a block instead of `with` ([flash-gordon](https://github.com/flash-gordon))
64
+ - `.decorate` can (again) work with static values. Also, it can take a block instead of `with` ([flash-gordon](https://github.com/flash-gordon))
10
65
  ```ruby
11
66
  container.register('key', 'value')
12
67
  container.decorate('key') { |v| "<'#{v}'>" }
13
68
  container.resolve('key') # => "<'value'>"
14
69
  ```
15
70
 
16
- [Compare v0.7.1...0.7.2](https://github.com/dry-rb/dry-container/compare/v0.7.1...v0.7.2)
17
71
 
18
- ## v0.7.1 - 2019-06-07
72
+ [Compare v0.7.1...v0.7.2](https://github.com/dry-rb/dry-container/compare/v0.7.1...v0.7.2)
19
73
 
20
- ## Fixed
74
+ ## 0.7.1 2019-06-07
21
75
 
22
- * Added `Mixin#dup` and `Mixin#clone`, now copies don't share underlying containers (flash-gordon)
23
76
 
24
- [Compare v0.7.0...0.7.1](https://github.com/dry-rb/dry-container/compare/v0.7.0...v0.7.1)
77
+ ### Fixed
25
78
 
26
- ## v0.7.0 - 2019-02-05
79
+ - Added `Mixin#dup` and `Mixin#clone`, now copies don't share underlying containers (flash-gordon)
27
80
 
28
- ## Changed
29
81
 
30
- * [BREAKING] Now only Ruby 2.3 and above is supported ([flash-gordon](https://github.com/flash-gordon))
82
+ [Compare v0.7.0...v0.7.1](https://github.com/dry-rb/dry-container/compare/v0.7.0...v0.7.1)
31
83
 
32
- ## Fixed
84
+ ## 0.7.0 2019-02-05
33
85
 
34
- * Symbols are now coerced to strings when resolving stubbed dependencies ([cthulhu666](https://github.com/cthulhu666))
35
- * Stubbing keys not present in container will raise an error ([flash-gordon](https://github.com/flash-gordon))
36
-
37
- This means after upgrading you may see errors like this
38
- ```
39
- ArgumentError (cannot stub "something" - no such key in container)
40
- ```
41
- Be sure you register dependencies before using them. The new behavior will likely save quite a bit of time when debugging ill-configured container setups.
42
86
 
43
- ## Added
87
+ ### Added
44
88
 
45
- * Namespace DSL resolves keys relative to the current namespace, see the corresponding [changes](https://github.com/dry-rb/dry-container/pull/47) ([yuszuv](https://github.com/yuszuv))
46
- * Registered objects can be decorated with the following API ([igor-alexandrov](https://github.com/igor-alexandrov))
89
+ - Namespace DSL resolves keys relative to the current namespace, see the corresponding [changes](https://github.com/dry-rb/dry-container/pull/47) ([yuszuv](https://github.com/yuszuv))
90
+ - Registered objects can be decorated with the following API ([igor-alexandrov](https://github.com/igor-alexandrov))
47
91
 
48
92
  ```ruby
49
93
  class CreateUser
@@ -59,34 +103,48 @@
59
103
  container.resolve('create_user')
60
104
  # => #<ShinyLogger @obj=#<CreateUser:0x...>]>
61
105
  ```
62
- * Freezing a container now prevents further registrations ([flash-gordon](https://github.com/flash-gordon))
106
+ - Freezing a container now prevents further registrations ([flash-gordon](https://github.com/flash-gordon))
107
+ - ## Internal
108
+ - Handling container items was generalized in [#34](https://github.com/dry-rb/dry-container/pull/34) ([GabrielMalakias](https://github.com/GabrielMalakias))
109
+
110
+ ### Fixed
111
+
112
+ - Symbols are now coerced to strings when resolving stubbed dependencies ([cthulhu666](https://github.com/cthulhu666))
113
+ - Stubbing keys not present in container will raise an error ([flash-gordon](https://github.com/flash-gordon))
114
+
115
+ This means after upgrading you may see errors like this
116
+ ```
117
+ ArgumentError (cannot stub "something" - no such key in container)
118
+ ```
119
+ Be sure you register dependencies before using them. The new behavior will likely save quite a bit of time when debugging ill-configured container setups.
120
+
121
+ ### Changed
122
+
123
+ - [BREAKING] Now only Ruby 2.3 and above is supported ([flash-gordon](https://github.com/flash-gordon))
63
124
 
64
- ## Internal
125
+ [Compare v0.6.0...v0.7.0](https://github.com/dry-rb/dry-container/compare/v0.6.0...v0.7.0)
65
126
 
66
- * Handling container items was generalized in [#34](https://github.com/dry-rb/dry-container/pull/34) ([GabrielMalakias](https://github.com/GabrielMalakias))
127
+ ## 0.6.0 2016-12-09
67
128
 
68
- [Compare v0.6.0...0.7.0](https://github.com/dry-rb/dry-container/compare/v0.6.0...v0.7.0)
69
129
 
70
- ## v0.6.0 - 2016-12-09
130
+ ### Added
71
131
 
72
- ## Added
132
+ - `Dry::Container::Mixin#each` - provides a means of seeing what all is registered in the container ([jeremyf](https://github.com/jeremyf))
73
133
 
74
- * `Dry::Container::Mixin#each` - provides a means of seeing what all is registered in the container ([jeremyf](https://github.com/jeremyf))
134
+ ### Fixed
75
135
 
76
- ## Fixed
136
+ - Including mixin into a class with a custom initializer ([maltoe](https://github.com/maltoe))
77
137
 
78
- * Including mixin into a class with a custom initializer ([maltoe](https://github.com/maltoe))
79
138
 
80
139
  [Compare v0.5.0...v0.6.0](https://github.com/dry-rb/dry-container/compare/v0.5.0...v0.6.0)
81
140
 
82
- ## v0.5.0 - 2016-08-31
141
+ ## 0.5.0 2016-08-31
83
142
 
84
- ## Added
85
143
 
86
- * `memoize` option to `#register` - memoizes items on first resolve ([ivoanjo](https://github.com/ivoanjo))
144
+ ### Added
87
145
 
88
- ## Fixed
146
+ - `memoize` option to `#register` - memoizes items on first resolve ([ivoanjo](https://github.com/ivoanjo))
89
147
 
90
- * `required_ruby_version` set to `>= 2.0.0` ([artofhuman](https://github.com/artofhuman))
148
+ ### Fixed
91
149
 
92
- [Compare v0.4.0...v0.5.0](https://github.com/dry-rb/dry-container/compare/v0.4.0...v0.5.0)
150
+ - `required_ruby_version` set to `>= 2.0.0` ([artofhuman](https://github.com/artofhuman))
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2017 dry-container
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
@@ -1,23 +1,29 @@
1
+ <!--- this file is synced from dry-rb/template-gem project -->
1
2
  [gem]: https://rubygems.org/gems/dry-container
2
- [travis]: https://travis-ci.org/dry-rb/dry-container
3
- [maintainability]: https://codeclimate.com/github/dry-rb/dry-container/maintainability
4
- [test_coverage]: https://codeclimate.com/github/dry-rb/dry-container/test_coverage
5
- [inch]: http://inch-ci.org/github/dry-rb/dry-container
3
+ [actions]: https://github.com/dry-rb/dry-container/actions
4
+ [codacy]: https://www.codacy.com/gh/dry-rb/dry-container
6
5
  [chat]: https://dry-rb.zulipchat.com
6
+ [inchpages]: http://inch-ci.org/github/dry-rb/dry-container
7
7
 
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
- [![Gem Version](https://img.shields.io/gem/v/dry-container.svg)][gem]
11
- [![Build Status](https://img.shields.io/travis/dry-rb/dry-container.svg)][travis]
12
- [![Maintainability](https://api.codeclimate.com/v1/badges/97faf9446cb5811100e7/maintainability)][maintainability]
13
- [![Test Coverage](https://api.codeclimate.com/v1/badges/97faf9446cb5811100e7/test_coverage)][test_coverage]
14
- [![API Documentation Coverage](http://inch-ci.org/github/dry-rb/dry-container.svg)][inch]
15
-
16
- A simple, configurable container implemented in Ruby.
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]
12
+ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/227509c9034340b493f769f6277f4ecb)][codacy]
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=main)][inchpages]
17
15
 
18
16
  ## Links
19
17
 
20
- [Documentation](http://dry-rb.org/gems/dry-container/)
18
+ * [User documentation](https://dry-rb.org/gems/dry-container)
19
+ * [API documentation](http://rubydoc.info/gems/dry-container)
20
+
21
+ ## Supported Ruby versions
22
+
23
+ This library officially supports the following Ruby versions:
24
+
25
+ * MRI `>= 2.7.0`
26
+ * jruby `>= 9.3` (postponed until 2.7 is supported)
21
27
 
22
28
  ## License
23
29
 
@@ -1,25 +1,37 @@
1
- require File.expand_path('../lib/dry/container/version', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ # this file is synced from dry-rb/template-gem project
4
+
5
+ lib = File.expand_path("lib", __dir__)
6
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
7
+ require "dry/container/version"
2
8
 
3
9
  Gem::Specification.new do |spec|
4
- spec.name = 'dry-container'
5
- spec.version = ::Dry::Container::VERSION
6
- spec.authors = ['Andy Holland']
7
- spec.email = ['andyholland1991@aol.com']
8
- spec.summary = 'A simple container intended for use as an IoC container'
9
- spec.homepage = 'https://github.com/dry-rb/dry-container'
10
- spec.license = 'MIT'
11
-
12
- spec.files = `git ls-files -z`.split("\x0")
13
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
- spec.require_paths = ['lib']
16
-
17
- spec.required_ruby_version = '>= 2.3.0'
18
-
19
- spec.add_runtime_dependency 'concurrent-ruby', '~> 1.0'
20
- spec.add_runtime_dependency 'dry-configurable', '~> 0.1', '>= 0.1.3'
21
-
22
- spec.add_development_dependency 'bundler'
23
- spec.add_development_dependency 'rake'
24
- spec.add_development_dependency 'rspec'
10
+ spec.name = "dry-container"
11
+ spec.authors = ["Andy Holland"]
12
+ spec.email = ["andyholland1991@aol.com"]
13
+ spec.license = "MIT"
14
+ spec.version = Dry::Container::VERSION.dup
15
+
16
+ spec.summary = "A simple, configurable object container implemented in Ruby"
17
+ spec.description = spec.summary
18
+ spec.homepage = "https://dry-rb.org/gems/dry-container"
19
+ spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-container.gemspec", "lib/**/*"]
20
+ spec.bindir = "bin"
21
+ spec.executables = []
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
25
+ spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-container/blob/master/CHANGELOG.md"
26
+ spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-container"
27
+ spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-container/issues"
28
+
29
+ spec.required_ruby_version = ">= 2.7.0"
30
+
31
+ # to update dependencies edit project.yml
32
+ spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
33
+
34
+ spec.add_development_dependency "bundler"
35
+ spec.add_development_dependency "rake"
36
+ spec.add_development_dependency "rspec"
25
37
  end
@@ -1,6 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dry
2
4
  class Container
3
5
  # @api public
4
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)
5
14
  end
6
15
  end
@@ -1,4 +1,6 @@
1
- require 'dry/container/item'
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/container/item"
2
4
 
3
5
  module Dry
4
6
  class Container
@@ -1,5 +1,7 @@
1
- require 'dry/container/item/memoizable'
2
- require 'dry/container/item/callable'
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/container/item/memoizable"
4
+ require "dry/container/item/callable"
3
5
 
4
6
  module Dry
5
7
  class Container
@@ -1,4 +1,6 @@
1
- require 'dry/container/item'
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/container/item"
2
4
 
3
5
  module Dry
4
6
  class Container
@@ -39,11 +41,9 @@ module Dry
39
41
 
40
42
  # @private
41
43
  def raise_not_supported_error
42
- 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"
43
45
  end
44
46
  end
45
47
  end
46
48
  end
47
49
  end
48
-
49
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dry
2
4
  class Container
3
5
  # Base class to abstract Memoizable and Callable implementations
@@ -1,8 +1,66 @@
1
+ # frozen_string_literal: true
1
2
 
2
- require 'concurrent/hash'
3
+ require "concurrent/hash"
3
4
 
4
5
  module Dry
5
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
+
6
64
  PREFIX_NAMESPACE = lambda do |namespace, key, config|
7
65
  [namespace, key].join(config.namespace_separator)
8
66
  end
@@ -30,8 +88,9 @@ module Dry
30
88
  # container.resolve(:item)
31
89
  # => 'item'
32
90
  #
33
- #
34
91
  # @api public
92
+ #
93
+ # rubocop:disable Metrics/ModuleLength
35
94
  module Mixin
36
95
  # @private
37
96
  def self.extended(base)
@@ -43,13 +102,9 @@ module Dry
43
102
  end
44
103
 
45
104
  base.class_eval do
46
- extend ::Dry::Configurable
105
+ extend Configuration
47
106
  extend hooks_mod
48
107
 
49
- setting :registry, ::Dry::Container::Registry.new
50
- setting :resolver, ::Dry::Container::Resolver.new
51
- setting :namespace_separator, '.'
52
-
53
108
  @_container = ::Concurrent::Hash.new
54
109
  end
55
110
  end
@@ -65,13 +120,9 @@ module Dry
65
120
  # @private
66
121
  def self.included(base)
67
122
  base.class_eval do
68
- extend ::Dry::Configurable
123
+ extend Configuration
69
124
  prepend Initializer
70
125
 
71
- setting :registry, ::Dry::Container::Registry.new
72
- setting :resolver, ::Dry::Container::Resolver.new
73
- setting :namespace_separator, '.'
74
-
75
126
  def config
76
127
  self.class.config
77
128
  end
@@ -104,6 +155,9 @@ module Dry
104
155
  config.registry.call(_container, key, item, options)
105
156
 
106
157
  self
158
+ rescue FrozenError
159
+ raise FrozenError,
160
+ "can't modify frozen #{self.class} (when attempting to register '#{key}')"
107
161
  end
108
162
 
109
163
  # Resolve an item from the container
@@ -144,15 +198,16 @@ module Dry
144
198
  # @return [Dry::Container::Mixin] self
145
199
  #
146
200
  # @api public
147
- def merge(other, namespace: nil)
201
+ def merge(other, namespace: nil, &block)
148
202
  if namespace
149
203
  _container.merge!(
150
- other._container.each_with_object(::Concurrent::Hash.new) do |a, h|
151
- h[PREFIX_NAMESPACE.call(namespace, a.first, config)] = a.last
152
- end
204
+ other._container.each_with_object(::Concurrent::Hash.new) { |(key, item), hsh|
205
+ hsh[PREFIX_NAMESPACE.call(namespace, key, config)] = item
206
+ },
207
+ &block
153
208
  )
154
209
  else
155
- _container.merge!(other._container)
210
+ _container.merge!(other._container, &block)
156
211
  end
157
212
 
158
213
  self
@@ -191,7 +246,8 @@ module Dry
191
246
  self
192
247
  end
193
248
 
194
- # Calls block once for each key/value pair in the container, passing the key and the registered item parameters.
249
+ # Calls block once for each key/value pair in the container, passing the key and
250
+ # the registered item parameters.
195
251
  #
196
252
  # If no block is given, an enumerator is returned instead.
197
253
  #
@@ -199,9 +255,9 @@ module Dry
199
255
  #
200
256
  # @api public
201
257
  #
202
- # @note In discussions with other developers, it was felt that being able to iterate over not just
203
- # the registered keys, but to see what was registered would be very helpful. This is a step
204
- # 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.
205
261
  def each(&block)
206
262
  config.resolver.each(_container, &block)
207
263
  end
@@ -292,5 +348,6 @@ module Dry
292
348
  copy
293
349
  end
294
350
  end
351
+ # rubocop:enable Metrics/ModuleLength
295
352
  end
296
353
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dry
2
4
  class Container
3
5
  # Create a namespace to be imported
@@ -22,6 +24,7 @@ module Dry
22
24
  attr_reader :name
23
25
  # @return [Proc] The block to be executed when the namespace is imported
24
26
  attr_reader :block
27
+
25
28
  # Create a new namespace
26
29
  #
27
30
  # @param [Mixed] name
@@ -1,4 +1,6 @@
1
- require 'delegate'
1
+ # frozen_string_literal: true
2
+
3
+ require "delegate"
2
4
 
3
5
  module Dry
4
6
  class Container
@@ -1,4 +1,6 @@
1
- require 'dry/container/item/factory'
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/container/item/factory"
2
4
 
3
5
  module Dry
4
6
  class Container
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dry
2
4
  class Container
3
5
  # Default resolver for resolving items from container
@@ -14,7 +16,7 @@ module Dry
14
16
  # Fallback block to call when a key is missing. Its result will be returned
15
17
  # @yieldparam [Mixed] key Missing key
16
18
  #
17
- # @raise [Dry::Conainer::Error]
19
+ # @raise [KeyError]
18
20
  # If the given key is not registered with the container (and no block provided)
19
21
  #
20
22
  #
@@ -26,7 +28,7 @@ module Dry
26
28
  if block_given?
27
29
  return yield(key)
28
30
  else
29
- raise Error, "Nothing registered with the key #{key.inspect}"
31
+ raise KeyError.new(%(key not found: "#{key}"), key: key.to_s, receiver: container)
30
32
  end
31
33
  end
32
34
 
@@ -67,16 +69,17 @@ module Dry
67
69
  container.each_key(&block)
68
70
  end
69
71
 
70
- # 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.
71
74
  #
72
75
  # If no block is given, an enumerator is returned instead.
73
76
  #
74
77
  # @return Key, Value
75
78
  #
76
79
  # @api public
77
- # @note In discussions with other developers, it was felt that being able to iterate over not just
78
- # the registered keys, but to see what was registered would be very helpful. This is a step
79
- # 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.
80
83
  def each(container, &block)
81
84
  container.map { |key, value| [key, value.call] }.each(&block)
82
85
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dry
2
4
  class Container
3
5
  module Stub
@@ -11,7 +13,7 @@ module Dry
11
13
  # Add a stub to the container
12
14
  def stub(key, value, &block)
13
15
  unless key?(key)
14
- raise ArgumentError, "cannot stub #{ key.to_s.inspect } - no such key in container"
16
+ raise ArgumentError, "cannot stub #{key.to_s.inspect} - no such key in container"
15
17
  end
16
18
 
17
19
  _stubs[key.to_s] = value
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dry
2
4
  class Container
3
5
  # @api public
4
- VERSION = '0.7.2'.freeze
6
+ VERSION = "0.11.0"
5
7
  end
6
8
  end