lib/dry/system/booter.rb in dry-system-0.18.2 vs lib/dry/system/booter.rb in dry-system-0.19.0

- old
+ new

@@ -29,21 +29,32 @@ @booted = [] @components = ComponentRegistry.new end # @api private - def bootable?(component) - !boot_file(component).nil? - end - - # @api private def register_component(component) components.register(component) self end + # Returns a bootable component if it can be found or loaded, otherwise nil + # + # @return [Dry::System::Components::Bootable, nil] # @api private + def find_component(name) + name = name.to_sym + + return components[name] if components.exists?(name) + + return if finalized? + + require_boot_file(name) + + components[name] if components.exists?(name) + end + + # @api private def finalize! boot_files.each do |path| load_component(path) end @@ -52,10 +63,17 @@ end freeze end + # @!method finalized? + # Returns true if the booter has been finalized + # + # @return [Boolean] + # @api private + alias_method :finalized?, :frozen? + # @api private def shutdown components.each do |component| next unless booted.include?(component) @@ -113,16 +131,23 @@ end end # @api private def boot_dependency(component) - boot_file = boot_file(component) - - start(boot_file.basename(".*").to_s.to_sym) if boot_file + if (component = find_component(component.root_key)) + start(component) + end end - # @api private + # Returns all boot files within the configured paths + # + # Searches for files in the order of the configured paths. In the case of multiple + # identically-named boot files within different paths, the file found first will be + # returned, and other matching files will be discarded. + # + # @return [Array<Pathname>] + # @api public def boot_files @boot_files ||= paths.each_with_object([[], []]) { |path, (boot_files, loaded)| files = Dir["#{path}/#{RB_GLOB}"].sort files.each do |file| @@ -157,15 +182,9 @@ identifier = Pathname(path).basename(RB_EXT).to_s.to_sym Kernel.require path unless components.exists?(identifier) self - end - - def boot_file(name) - name = name.respond_to?(:root_key) ? name.root_key.to_s : name - - find_boot_file(name) end def require_boot_file(identifier) boot_file = find_boot_file(identifier)