Skip to content

Commit

Permalink
Rename manual registrar to manifest registrar (#208)
Browse files Browse the repository at this point in the history
This will allow us to reserve the term "manual registration" for any instance of a user directly calling `#register` on the container.
  • Loading branch information
timriley authored Jan 14, 2022
1 parent 5679b57 commit ca46102
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 20 deletions.
22 changes: 11 additions & 11 deletions lib/dry/system/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -321,7 +321,7 @@ def finalize!(freeze: true, &block)

importer.finalize!
providers.finalize!
manual_registrar.finalize!
manifest_registrar.finalize!
auto_registrar.finalize!

@__finalized__ = true
Expand Down Expand Up @@ -412,7 +412,7 @@ def add_to_load_path!(*dirs)

# @api public
def load_registrations!(name)
manual_registrar.(name)
manifest_registrar.(name)
self
end

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/system/indirect_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# 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")
end
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
Expand Down

0 comments on commit ca46102

Please sign in to comment.