dry-container 0.7.2 → 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: ac1a656d67e37d72da3265e2f092e507460cba4615db8f3727ee1acbca41584c
4
- data.tar.gz: be191bd45d43147d12c858d8683463be5e59a66ef2f473e8c19d7010bda0794c
3
+ metadata.gz: 1142596b0e507d66a8d2fc50b0e547e562194002a66b560945b386007fee17ae
4
+ data.tar.gz: 01a300ee230fa9047f002d90c0a02fe8d80da49e56706deb2a29da67d2e1ea08
5
5
  SHA512:
6
- metadata.gz: c95deccc6ad3f976d31949d1a39e1bc4d6f5797604045aed3f7254d3a1e88ca35c76ee0483ad14bbc6abe0aed8fb13d157cd793c6eb1ff417343a0037a56358f
7
- data.tar.gz: a6bac7cb3f1819b6bb89a2989de1fe0c3d9a182144a556394cec1f8a1d48bf848589c57ffc7b4daaac106cb0a5673b086f901f2b1deba81c64796a6a1038c6c0
6
+ metadata.gz: 7df2087f89345b9e5225f24226b7b20a2beceec88ebd424fa4a759808f7df1b355d2771370b4fbdc26d536891a68bd0c1f5b9353cb2301d10c80787466f59eaa
7
+ data.tar.gz: 3d83f9c597b41ad3b446ee0f1441ed42b443ac70ad0775bd17d8d5947fdf2508bf0f883e5f298ec16e908cd07bb7966f3688fba9ccd5606d76c400a76d0822c9
data/CHANGELOG.md CHANGED
@@ -1,49 +1,75 @@
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.10.0 2022-07-10
4
4
 
5
- * `.resolve` accepts an optional fallback block, similar to how `Hash#fetch` works ([flash-gordon](https://github.com/flash-gordon))
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
+
19
+ ## 0.9.0 2021-09-12
20
+
21
+
22
+ ### Changed
23
+
24
+ - [internal] Upgraded to new `setting` API provided in dry-configurable 0.13.0 (@timriley in #77)
25
+
26
+ [Compare v0.8.0...v0.9.0](https://github.com/dry-rb/dry-container/compare/v0.8.0...v0.9.0)
27
+
28
+ ## 0.8.0 2021-06-06
29
+
30
+
31
+ ### Changed
32
+
33
+ - [BREAKING] Support for 2.4 and 2.5 was dropped
34
+
35
+ [Compare v0.7.2...v0.8.0](https://github.com/dry-rb/dry-container/compare/v0.7.2...v0.8.0)
36
+
37
+ ## 0.7.2 2019-07-09
38
+
39
+
40
+ ### Added
41
+
42
+ - `.resolve` accepts an optional fallback block, similar to how `Hash#fetch` works ([flash-gordon](https://github.com/flash-gordon))
6
43
  ```ruby
7
44
  container.resolve('missing_key') { :fallback } # => :fallback
8
45
  ```
9
- * `.decorate` can (again) work with static values. Also, it can take a block instead of `with` ([flash-gordon](https://github.com/flash-gordon))
46
+ - `.decorate` can (again) work with static values. Also, it can take a block instead of `with` ([flash-gordon](https://github.com/flash-gordon))
10
47
  ```ruby
11
48
  container.register('key', 'value')
12
49
  container.decorate('key') { |v| "<'#{v}'>" }
13
50
  container.resolve('key') # => "<'value'>"
14
51
  ```
15
52
 
16
- [Compare v0.7.1...0.7.2](https://github.com/dry-rb/dry-container/compare/v0.7.1...v0.7.2)
17
53
 
18
- ## v0.7.1 - 2019-06-07
54
+ [Compare v0.7.1...v0.7.2](https://github.com/dry-rb/dry-container/compare/v0.7.1...v0.7.2)
19
55
 
20
- ## Fixed
56
+ ## 0.7.1 2019-06-07
21
57
 
22
- * Added `Mixin#dup` and `Mixin#clone`, now copies don't share underlying containers (flash-gordon)
23
58
 
24
- [Compare v0.7.0...0.7.1](https://github.com/dry-rb/dry-container/compare/v0.7.0...v0.7.1)
59
+ ### Fixed
25
60
 
26
- ## v0.7.0 - 2019-02-05
61
+ - Added `Mixin#dup` and `Mixin#clone`, now copies don't share underlying containers (flash-gordon)
27
62
 
28
- ## Changed
29
63
 
30
- * [BREAKING] Now only Ruby 2.3 and above is supported ([flash-gordon](https://github.com/flash-gordon))
64
+ [Compare v0.7.0...v0.7.1](https://github.com/dry-rb/dry-container/compare/v0.7.0...v0.7.1)
31
65
 
32
- ## Fixed
66
+ ## 0.7.0 2019-02-05
33
67
 
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
68
 
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
-
43
- ## Added
69
+ ### Added
44
70
 
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))
71
+ - 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))
72
+ - Registered objects can be decorated with the following API ([igor-alexandrov](https://github.com/igor-alexandrov))
47
73
 
48
74
  ```ruby
49
75
  class CreateUser
@@ -59,34 +85,48 @@
59
85
  container.resolve('create_user')
60
86
  # => #<ShinyLogger @obj=#<CreateUser:0x...>]>
61
87
  ```
62
- * Freezing a container now prevents further registrations ([flash-gordon](https://github.com/flash-gordon))
88
+ - Freezing a container now prevents further registrations ([flash-gordon](https://github.com/flash-gordon))
89
+ - ## Internal
90
+ - Handling container items was generalized in [#34](https://github.com/dry-rb/dry-container/pull/34) ([GabrielMalakias](https://github.com/GabrielMalakias))
91
+
92
+ ### Fixed
93
+
94
+ - Symbols are now coerced to strings when resolving stubbed dependencies ([cthulhu666](https://github.com/cthulhu666))
95
+ - Stubbing keys not present in container will raise an error ([flash-gordon](https://github.com/flash-gordon))
96
+
97
+ This means after upgrading you may see errors like this
98
+ ```
99
+ ArgumentError (cannot stub "something" - no such key in container)
100
+ ```
101
+ 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.
102
+
103
+ ### Changed
104
+
105
+ - [BREAKING] Now only Ruby 2.3 and above is supported ([flash-gordon](https://github.com/flash-gordon))
63
106
 
64
- ## Internal
107
+ [Compare v0.6.0...v0.7.0](https://github.com/dry-rb/dry-container/compare/v0.6.0...v0.7.0)
65
108
 
66
- * Handling container items was generalized in [#34](https://github.com/dry-rb/dry-container/pull/34) ([GabrielMalakias](https://github.com/GabrielMalakias))
109
+ ## 0.6.0 2016-12-09
67
110
 
68
- [Compare v0.6.0...0.7.0](https://github.com/dry-rb/dry-container/compare/v0.6.0...v0.7.0)
69
111
 
70
- ## v0.6.0 - 2016-12-09
112
+ ### Added
71
113
 
72
- ## Added
114
+ - `Dry::Container::Mixin#each` - provides a means of seeing what all is registered in the container ([jeremyf](https://github.com/jeremyf))
73
115
 
74
- * `Dry::Container::Mixin#each` - provides a means of seeing what all is registered in the container ([jeremyf](https://github.com/jeremyf))
116
+ ### Fixed
75
117
 
76
- ## Fixed
118
+ - Including mixin into a class with a custom initializer ([maltoe](https://github.com/maltoe))
77
119
 
78
- * Including mixin into a class with a custom initializer ([maltoe](https://github.com/maltoe))
79
120
 
80
121
  [Compare v0.5.0...v0.6.0](https://github.com/dry-rb/dry-container/compare/v0.5.0...v0.6.0)
81
122
 
82
- ## v0.5.0 - 2016-08-31
123
+ ## 0.5.0 2016-08-31
83
124
 
84
- ## Added
85
125
 
86
- * `memoize` option to `#register` - memoizes items on first resolve ([ivoanjo](https://github.com/ivoanjo))
126
+ ### Added
87
127
 
88
- ## Fixed
128
+ - `memoize` option to `#register` - memoizes items on first resolve ([ivoanjo](https://github.com/ivoanjo))
89
129
 
90
- * `required_ruby_version` set to `>= 2.0.0` ([artofhuman](https://github.com/artofhuman))
130
+ ### Fixed
91
131
 
92
- [Compare v0.4.0...v0.5.0](https://github.com/dry-rb/dry-container/compare/v0.4.0...v0.5.0)
132
+ - `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,13 @@
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
+ DidYouMean.correct_error(KeyError, DidYouMean::KeyErrorChecker)
10
+
11
+ deprecate_constant(:Error)
5
12
  end
6
13
  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,64 @@
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
+ 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
+
6
62
  PREFIX_NAMESPACE = lambda do |namespace, key, config|
7
63
  [namespace, key].join(config.namespace_separator)
8
64
  end
@@ -30,7 +86,6 @@ module Dry
30
86
  # container.resolve(:item)
31
87
  # => 'item'
32
88
  #
33
- #
34
89
  # @api public
35
90
  module Mixin
36
91
  # @private
@@ -43,13 +98,9 @@ module Dry
43
98
  end
44
99
 
45
100
  base.class_eval do
46
- extend ::Dry::Configurable
101
+ extend Configuration
47
102
  extend hooks_mod
48
103
 
49
- setting :registry, ::Dry::Container::Registry.new
50
- setting :resolver, ::Dry::Container::Resolver.new
51
- setting :namespace_separator, '.'
52
-
53
104
  @_container = ::Concurrent::Hash.new
54
105
  end
55
106
  end
@@ -65,13 +116,9 @@ module Dry
65
116
  # @private
66
117
  def self.included(base)
67
118
  base.class_eval do
68
- extend ::Dry::Configurable
119
+ extend Configuration
69
120
  prepend Initializer
70
121
 
71
- setting :registry, ::Dry::Container::Registry.new
72
- setting :resolver, ::Dry::Container::Resolver.new
73
- setting :namespace_separator, '.'
74
-
75
122
  def config
76
123
  self.class.config
77
124
  end
@@ -104,6 +151,9 @@ module Dry
104
151
  config.registry.call(_container, key, item, options)
105
152
 
106
153
  self
154
+ rescue FrozenError
155
+ raise FrozenError,
156
+ "can't modify frozen #{self.class} (when attempting to register '#{key}')"
107
157
  end
108
158
 
109
159
  # Resolve an item from the container
@@ -144,15 +194,16 @@ module Dry
144
194
  # @return [Dry::Container::Mixin] self
145
195
  #
146
196
  # @api public
147
- def merge(other, namespace: nil)
197
+ def merge(other, namespace: nil, &block)
148
198
  if namespace
149
199
  _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
200
+ other._container.each_with_object(::Concurrent::Hash.new) { |(key, item), hsh|
201
+ hsh[PREFIX_NAMESPACE.call(namespace, key, config)] = item
202
+ },
203
+ &block
153
204
  )
154
205
  else
155
- _container.merge!(other._container)
206
+ _container.merge!(other._container, &block)
156
207
  end
157
208
 
158
209
  self
@@ -191,7 +242,8 @@ module Dry
191
242
  self
192
243
  end
193
244
 
194
- # 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.
195
247
  #
196
248
  # If no block is given, an enumerator is returned instead.
197
249
  #
@@ -199,9 +251,9 @@ module Dry
199
251
  #
200
252
  # @api public
201
253
  #
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.
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.
205
257
  def each(&block)
206
258
  config.resolver.each(_container, &block)
207
259
  end
@@ -292,5 +344,6 @@ module Dry
292
344
  copy
293
345
  end
294
346
  end
347
+ # rubocop: enable Metrics/ModuleLength
295
348
  end
296
349
  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.10.0"
5
7
  end
6
8
  end
data/lib/dry/container.rb CHANGED
@@ -1,11 +1,12 @@
1
- require 'dry-configurable'
2
- require 'dry/container/error'
3
- require 'dry/container/namespace'
4
- require 'dry/container/registry'
5
- require 'dry/container/resolver'
6
- require 'dry/container/namespace_dsl'
7
- require 'dry/container/mixin'
8
- require 'dry/container/version'
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/container/error"
4
+ require "dry/container/namespace"
5
+ require "dry/container/registry"
6
+ require "dry/container/resolver"
7
+ require "dry/container/namespace_dsl"
8
+ require "dry/container/mixin"
9
+ require "dry/container/version"
9
10
 
10
11
  # A collection of micro-libraries, each intended to encapsulate
11
12
  # a common task in Ruby
data/lib/dry-container.rb CHANGED
@@ -1 +1,3 @@
1
- require 'dry/container'
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/container"