dry-container 0.8.0 → 0.10.1
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 +43 -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 +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: fc4f775005011815006af0b6767d39de83abe44c314d6950491ecefed635f0ce
         | 
| 4 | 
            +
              data.tar.gz: 2240b5954ba883e33c0c66d10eaa0193e8e72906a7c1b6d8d774c1717a2a2552
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 2d006b7390ea827fdac570294f98bff3b6e77af12976f84f0eaf3f4e6ff3fd4ef8fa65ddfbcc9ae4f4f1144742113817682bd13013e02241e51c01ccde8f39e4
         | 
| 7 | 
            +
              data.tar.gz: 4a9726b3ce4e53d516f2c5183369f4061f3d5a1f60e93957c7a04725e0d024481cf85b0420ad8e5a18e547015843e7103d15ff6254a6d311de2db357fc464ac6
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -1,5 +1,48 @@ | |
| 1 1 | 
             
            <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
         | 
| 2 2 |  | 
| 3 | 
            +
            ## 0.10.1 2022-07-29
         | 
| 4 | 
            +
             | 
| 5 | 
            +
             | 
| 6 | 
            +
            ### Changed
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            - Make `DidYouMean` integration optional (via #86) (@jbourassa)
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            [Compare v0.10.0...v0.10.1](https://github.com/dry-rb/dry-container/compare/v0.10.0...v0.10.1)
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            ## 0.10.0 2022-07-10
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            ⚠️ 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.
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            ### Added
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            - Accept block given to `#merge` (via #83) (@timriley)
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            ### Changed
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            - [BREAKING] Replace dep on dry-configurable with a simple `Configuration` mod (see #84 for more details) (@solnic)
         | 
| 23 | 
            +
            - Raise KeyError for missing key, with DidYouMean integration (via #82) (@cllns)
         | 
| 24 | 
            +
            - Wrap FrozenError, to state that the container itself is frozen (see #74) (@cllns)
         | 
| 25 | 
            +
             | 
| 26 | 
            +
            [Compare v0.9.0...v0.10.0](https://github.com/dry-rb/dry-container/compare/v0.9.0...v0.10.0)
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            ## 0.9.0 2021-09-12
         | 
| 29 | 
            +
             | 
| 30 | 
            +
             | 
| 31 | 
            +
            ### Changed
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            - [internal] Upgraded to new `setting` API provided in dry-configurable 0.13.0 (@timriley in #77)
         | 
| 34 | 
            +
             | 
| 35 | 
            +
            [Compare v0.8.0...v0.9.0](https://github.com/dry-rb/dry-container/compare/v0.8.0...v0.9.0)
         | 
| 36 | 
            +
             | 
| 37 | 
            +
            ## 0.8.0 2021-06-06
         | 
| 38 | 
            +
             | 
| 39 | 
            +
             | 
| 40 | 
            +
            ### Changed
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            - [BREAKING] Support for 2.4 and 2.5 was dropped
         | 
| 43 | 
            +
             | 
| 44 | 
            +
            [Compare v0.7.2...v0.8.0](https://github.com/dry-rb/dry-container/compare/v0.7.2...v0.8.0)
         | 
| 45 | 
            +
             | 
| 3 46 | 
             
            ## 0.7.2 2019-07-09
         | 
| 4 47 |  | 
| 5 48 |  | 
    
        data/LICENSE
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -11,7 +11,7 @@ | |
| 11 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 | 
            -
            * 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,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, ::Dry::Container::Registry.new
         | 
| 51 | 
            -
                      setting :resolver, ::Dry::Container::Resolver.new
         | 
| 52 | 
            -
                      setting :namespace_separator, "."
         | 
| 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, ::Dry::Container::Registry.new
         | 
| 73 | 
            -
                      setting :resolver, ::Dry::Container::Resolver.new
         | 
| 74 | 
            -
                      setting :namespace_separator, "."
         | 
| 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.1
         | 
| 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-29 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 | 
             
              - - ">="
         |