lib/dry/system/container.rb in dry-system-0.27.2 vs lib/dry/system/container.rb in dry-system-1.0.0.rc1

- old
+ new

@@ -2,11 +2,10 @@ require "pathname" require "dry/configurable" require "dry/auto_inject" -require "dry/container" require "dry/inflector" module Dry module System # Abstract container class to inherit from @@ -51,17 +50,16 @@ # add_dirs_to_load_paths!('lib') # end # # @api public class Container - extend Dry::Container::Mixin + extend Dry::Core::Container::Mixin extend Dry::System::Plugins setting :name setting :root, default: Pathname.pwd.freeze, constructor: ->(path) { Pathname(path) } setting :provider_dirs, default: ["system/providers"] - setting :bootable_dirs # Deprecated for provider_dirs, see .provider_paths below setting :registrations_dir, default: "system/registrations" setting :component_dirs, default: Config::ComponentDirs.new, cloneable: true setting :exports, reader: true setting :inflector, default: Dry::Inflector.new setting :auto_registrar, default: Dry::System::AutoRegistrar @@ -71,12 +69,10 @@ # Expect "." as key namespace separator. This is not intended to be user-configurable. config.namespace_separator = KEY_SEPARATOR class << self - extend Dry::Core::Deprecations["Dry::System::Container"] - # @!method config # Returns the configuration for the container # # @example # container.config.root = "/path/to/app" @@ -150,51 +146,40 @@ # Registers another container for import # # @example # # system/container.rb + # require "dry/system/container" + # require "logger" + # # class Core < Dry::System::Container - # configure do |config| - # config.root = Pathname("/path/to/app") - # config.auto_register = %w(lib/apis lib/core) - # end + # register("logger", Logger.new($stdout)) # end # # # apps/my_app/system/container.rb # require 'system/container' # # class MyApp < Dry::System::Container - # configure do |config| - # config.root = Pathname("/path/to/app") - # config.auto_register = %w(lib/apis lib/core) - # end - # - # import core: Core + # import(from: Core, as: :core) # end # - # @param other [Hash, Dry::Container::Namespace] + # MyApp.import(keys: ["logger"], from: Core, as: :core2) # + # MyApp["core.logger"].info("Test") + # MyApp["core2.logger"].info("Test2") + # + # @param keys [Array<String>] Keys for the components to import + # @param from [Class] The container to import from + # @param as [Symbol] Namespace to use for the components of the imported container + # + # @raise [Dry::System::ContainerAlreadyFinalizedError] if the container has already + # been finalized + # # @api public - def import(keys: nil, from: Undefined, as: Undefined, **deprecated_import_hash) - if deprecated_import_hash.any? - Dry::Core::Deprecations.announce( - "Dry::System::Container.import with {namespace => container} hash", - "Use Dry::System::Container.import(from: container, as: namespace) instead", - tag: "dry-system", - uplevel: 1 - ) + def import(from:, as:, keys: nil) + raise Dry::System::ContainerAlreadyFinalizedError if finalized? - deprecated_import_hash.each do |namespace, container| - importer.register(container: container, namespace: namespace) - end - return self - elsif from == Undefined || as == Undefined - # These keyword arguments can become properly required in the params list once - # we remove the deprecation shim above - raise ArgumentError, "required keyword arguments: :from, :as" - end - importer.register(container: from, namespace: as, keys: keys) self end @@ -289,30 +274,10 @@ providers.register_provider(...) end # rubocop:enable Layout/LineLength - # @see .register_provider - # @api public - def boot(name, **opts, &block) - Dry::Core::Deprecations.announce( - "Dry::System::Container.boot", - "Use `Dry::System::Container.register_provider` instead", - tag: "dry-system", - uplevel: 1 - ) - - register_provider( - name, - namespace: opts[:namespace], - from: opts[:from], - source: opts[:key], - &block - ) - end - deprecate :finalize, :boot - # Return if a container was finalized # # @return [TrueClass, FalseClass] # # @api public @@ -401,11 +366,10 @@ # @api public def prepare(name) providers.prepare(name) self end - deprecate :init, :prepare # Stop a specific component but calls only `stop` lifecycle trigger # # @example # MyApp.stop(:persistence) @@ -561,10 +525,9 @@ # @api private def providers @providers ||= config.provider_registrar.new(self) end - deprecate :booter, :providers # @api private def auto_registrar @auto_registrar ||= config.auto_registrar.new(self) end