diff --git a/lib/dry/system/container.rb b/lib/dry/system/container.rb index b1d9df2f..3cce308d 100644 --- a/lib/dry/system/container.rb +++ b/lib/dry/system/container.rb @@ -18,7 +18,7 @@ require "dry/system/identifier" require "dry/system/importer" require "dry/system/indirect_component" -require "dry/system/manual_registrar" +require "dry/system/manifest_registrar" require "dry/system/plugins" require "dry/system/provider_registrar" require "dry/system/provider" @@ -81,11 +81,11 @@ class Container 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: "container" + setting :registrations_dir, default: "system/registrations" setting :component_dirs, default: Config::ComponentDirs.new, cloneable: true setting :inflector, default: Dry::Inflector.new setting :auto_registrar, default: Dry::System::AutoRegistrar - setting :manual_registrar, default: Dry::System::ManualRegistrar + setting :manifest_registrar, default: Dry::System::ManifestRegistrar setting :provider_registrar, default: Dry::System::ProviderRegistrar setting :importer, default: Dry::System::Importer @@ -321,7 +321,7 @@ def finalize!(freeze: true, &block) importer.finalize! providers.finalize! - manual_registrar.finalize! + manifest_registrar.finalize! auto_registrar.finalize! @__finalized__ = true @@ -412,7 +412,7 @@ def add_to_load_path!(*dirs) # @api public def load_registrations!(name) - manual_registrar.(name) + manifest_registrar.(name) self end @@ -563,8 +563,8 @@ def auto_registrar end # @api private - def manual_registrar - @manual_registrar ||= config.manual_registrar.new(self) + def manifest_registrar + @manifest_registrar ||= config.manifest_registrar.new(self) end # @api private @@ -616,8 +616,8 @@ def load_component(key) if component.loadable? load_local_component(component) - elsif manual_registrar.file_exists?(component) - manual_registrar.(component) + elsif manifest_registrar.file_exists?(component) + manifest_registrar.(component) elsif importer.key?(component.identifier.root_key) load_imported_component(component.identifier) end @@ -646,8 +646,8 @@ def load_imported_component(identifier) def find_component(key) # Find the first matching component from within the configured component dirs. # If no matching component is found, return a null component; this fallback is - # important because the component may still be loadable via the manual registrar - # or an imported container. + # important because the component may still be loadable via the manifest + # registrar or an imported container. component_dirs.detect { |dir| if (component = dir.component_for_key(key)) break component diff --git a/lib/dry/system/indirect_component.rb b/lib/dry/system/indirect_component.rb index c943678d..0b29bec8 100644 --- a/lib/dry/system/indirect_component.rb +++ b/lib/dry/system/indirect_component.rb @@ -6,7 +6,7 @@ module Dry module System # An indirect component is a component that cannot be directly from a source file # directly managed by the container. It may be component that needs to be loaded - # indirectly, either via a manual registration file or an imported container + # indirectly, either via a registration manifest file or an imported container # # Indirect components are an internal abstraction and, unlike ordinary components, are # not exposed to users via component dir configuration hooks. diff --git a/lib/dry/system/manual_registrar.rb b/lib/dry/system/manifest_registrar.rb similarity index 74% rename from lib/dry/system/manual_registrar.rb rename to lib/dry/system/manifest_registrar.rb index 7f888a49..62c7fded 100644 --- a/lib/dry/system/manual_registrar.rb +++ b/lib/dry/system/manifest_registrar.rb @@ -4,19 +4,21 @@ module Dry module System - # Default manual registration implementation + # Default manifest registration implementation # - # This is currently configured by default for every System::Container. - # Manual registrar objects are responsible for loading files from configured - # manual registration paths, which should hold code to explicitly register + # This is configured by default for every System::Container. The manifest registrar is + # responsible for loading manifest files that contain code to manually register # certain objects with the container. # # @api private - class ManualRegistrar + class ManifestRegistrar + # @api private attr_reader :container + # @api private attr_reader :config + # @api private def initialize(container) @container = container @config = container.config @@ -34,6 +36,7 @@ def call(component) require(root.join(config.registrations_dir, component.root_key.to_s)) end + # @api private def file_exists?(component) File.exist?(File.join(registrations_dir, "#{component.root_key}#{RB_EXT}")) end diff --git a/spec/fixtures/manual_registration/lib/test/foo.rb b/spec/fixtures/manifest_registration/lib/test/foo.rb similarity index 100% rename from spec/fixtures/manual_registration/lib/test/foo.rb rename to spec/fixtures/manifest_registration/lib/test/foo.rb diff --git a/spec/fixtures/manual_registration/container/foo.rb b/spec/fixtures/manifest_registration/system/registrations/foo.rb similarity index 100% rename from spec/fixtures/manual_registration/container/foo.rb rename to spec/fixtures/manifest_registration/system/registrations/foo.rb diff --git a/spec/integration/container/lazy_loading/manual_registration_spec.rb b/spec/integration/container/lazy_loading/manifest_registration_spec.rb similarity index 60% rename from spec/integration/container/lazy_loading/manual_registration_spec.rb rename to spec/integration/container/lazy_loading/manifest_registration_spec.rb index 4344152a..567955b2 100644 --- a/spec/integration/container/lazy_loading/manual_registration_spec.rb +++ b/spec/integration/container/lazy_loading/manifest_registration_spec.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -RSpec.describe "Lazy-loading manual registration files" do +RSpec.describe "Lazy-loading registration manifest files" do before do module Test class Container < Dry::System::Container configure do |config| - config.root = SPEC_ROOT.join("fixtures/manual_registration").realpath + config.root = SPEC_ROOT.join("fixtures/manifest_registration").realpath end add_to_load_path!("lib") @@ -13,7 +13,7 @@ class Container < Dry::System::Container end end - it "loads a manual registration file if the component could not be found" do + it "loads a registration manifest file if the component could not be found" do expect(Test::Container["foo.special"]).to be_a(Test::Foo) expect(Test::Container["foo.special"].name).to eq "special" end