lib/dry/system/container.rb in dry-system-0.7.2 vs lib/dry/system/container.rb in dry-system-0.7.3
- old
+ new
@@ -78,10 +78,11 @@
setting :manual_registrar, Dry::System::ManualRegistrar
setting :importer, Dry::System::Importer
class << self
extend Dry::Core::Deprecations['Dry::System::Container']
+
# Configures the container
#
# @example
# class MyApp < Dry::System::Container
# configure do |config|
@@ -211,10 +212,19 @@
def finalize(name, &block)
booter[name] = [self, block]
self
end
+ # Return if a container was finalized
+ #
+ # @return [TrueClass, FalseClass]
+ #
+ # @api public
+ def finalized?
+ @__finalized__.equal?(true)
+ end
+
# Finalizes the container
#
# This triggers importing components from other containers, booting
# registered components and auto-registering components. It should be
# called only in places where you want to finalize your system as a
@@ -241,19 +251,21 @@
#
# @return [self] frozen container
#
# @api public
def finalize!(freeze: true, &block)
- return self if frozen?
+ return self if finalized?
yield(self) if block
importer.finalize!
booter.finalize!
manual_registrar.finalize!
auto_registrar.finalize!
+ @__finalized__ = true
+
self.freeze if freeze
end
# Boots a specific component
#
@@ -431,11 +443,11 @@
config.root
end
# @api public
def resolve(key)
- load_component(key) unless frozen?
+ load_component(key) unless finalized?
super
end
# @api private
@@ -507,10 +519,10 @@
private
# @api private
def load_local_component(component, default_namespace_fallback = false)
if component.bootable?(booter.path) || component.file_exists?(load_paths)
- booter.boot_dependency(component) unless frozen?
+ booter.boot_dependency(component) unless finalized?
require_component(component) do
register(component.identifier) { component.instance }
end
elsif !default_namespace_fallback