Module: Dry::System

Includes:
Core::Constants
Defined in:
lib/dry/system.rb,
lib/dry/system/stubs.rb,
lib/dry/system/errors.rb,
lib/dry/system/loader.rb,
lib/dry/system/plugins.rb,
lib/dry/system/version.rb,
lib/dry/system/importer.rb,
lib/dry/system/provider.rb,
lib/dry/system/component.rb,
lib/dry/system/constants.rb,
lib/dry/system/container.rb,
lib/dry/system/identifier.rb,
lib/dry/system/plugins/env.rb,
lib/dry/system/component_dir.rb,
lib/dry/system/auto_registrar.rb,
lib/dry/system/plugins/plugin.rb,
lib/dry/system/plugins/logging.rb,
lib/dry/system/provider/source.rb,
lib/dry/system/config/namespace.rb,
lib/dry/system/plugins/bootsnap.rb,
lib/dry/system/plugins/zeitwerk.rb,
lib/dry/system/config/namespaces.rb,
lib/dry/system/indirect_component.rb,
lib/dry/system/loader/autoloading.rb,
lib/dry/system/manifest_registrar.rb,
lib/dry/system/plugins/monitoring.rb,
lib/dry/system/provider_registrar.rb,
lib/dry/system/provider/source_dsl.rb,
lib/dry/system/config/component_dir.rb,
lib/dry/system/config/component_dirs.rb,
lib/dry/system/magic_comments_parser.rb,
lib/dry/system/plugins/notifications.rb,
lib/dry/system/plugins/dependency_graph.rb,
lib/dry/system/plugins/monitoring/proxy.rb,
lib/dry/system/provider_source_registry.rb,
lib/dry/system/provider_sources/settings.rb,
lib/dry/system/provider_sources/settings/config.rb,
lib/dry/system/provider_sources/settings/loader.rb,
lib/dry/system/plugins/zeitwerk/compat_inflector.rb,
lib/dry/system/plugins/dependency_graph/strategies.rb

Defined Under Namespace

Modules: Config, Plugins, ProviderSources Classes: AutoRegistrar, Component, ComponentDir, Container, Identifier, Importer, IndirectComponent, Loader, MagicCommentsParser, ManifestRegistrar, Provider, ProviderRegistrar, ProviderSourceRegistry

Constant Summary collapse

ContainerAlreadyFinalizedError =

Error raised when import is called on an already finalized container

Class.new(StandardError)
ComponentDirAlreadyAddedError =

Error raised when a component dir is added to configuration more than once

Class.new(StandardError) do
  def initialize(dir)
    super("Component directory #{dir.inspect} already added")
  end
end
ComponentDirNotFoundError =

Error raised when a configured component directory could not be found

Class.new(StandardError) do
  def initialize(dir)
    super("Component dir '#{dir}' not found")
  end
end
NamespaceAlreadyAddedError =

Error raised when a namespace for a component dir is added to configuration more than once

Class.new(StandardError) do
  def initialize(path)
    path_label = path ? "path #{path.inspect}" : "root path"

    super("Namespace for #{path_label} already added")
  end
end
ProviderAlreadyRegisteredError =

Error raised when attempting to register provider using a name that has already been registered

Class.new(ArgumentError) do
  def initialize(provider_name)
    super("Provider #{provider_name.inspect} has already been registered")
  end
end
ProviderNotFoundError =

Error raised when a named provider could not be found

Class.new(ArgumentError) do
  def initialize(name)
    super("Provider #{name.inspect} not found")
  end
end
ProviderSourceNotFoundError =

Error raised when a named provider source could not be found

Class.new(StandardError) do
  def initialize(name:, group:, keys:)
    msg = "Provider source not found: #{name.inspect}, group: #{group.inspect}"

    key_list = keys.map { |key| "- #{key[:name].inspect}, group: #{key[:group].inspect}" }
    msg += "Available provider sources:\n\n#{key_list}"

    super(msg)
  end
end
PluginNotFoundError =

Error raised when trying to use a plugin that does not exist.

Class.new(StandardError) do
  def initialize(plugin_name)
    super("Plugin #{plugin_name.inspect} does not exist")
  end
end
PluginDependencyMissing =

Exception raise when a plugin dependency failed to load

Class.new(StandardError) do
  # @api private
  def initialize(plugin, message, gem = nil)
    details = gem ? "#{message} - add #{gem} to your Gemfile" : message
    super("dry-system plugin #{plugin.inspect} failed to load its dependencies: #{details}")
  end
end
ComponentNotLoadableError =

Exception raised when auto-registerable component is not loadable

Class.new(NameError) do
  # @api private
  def initialize(component, error,
                 corrections: DidYouMean::ClassNameChecker.new(error).corrections)
    full_class_name = [error.receiver, error.name].join("::")

    message = [
      "Component '#{component.key}' is not loadable.",
      "Looking for #{full_class_name}."
    ]

    if corrections.any?
      case_correction = corrections.find { |correction| correction.casecmp?(full_class_name) }
      if case_correction
        acronyms_needed = case_correction.split("::").difference(full_class_name.split("::"))
        stringified_acronyms_needed = acronyms_needed.map { |acronym|
          "'#{acronym}'"
        } .join(", ")
        message <<
          <<~ERROR_MESSAGE

            You likely need to add:

                acronym(#{stringified_acronyms_needed})

            to your container's inflector, since we found a #{case_correction} class.
          ERROR_MESSAGE
      else
        message << DidYouMean.formatter.message_for(corrections)
      end
    end

    super message.join("\n")
  end
end
VERSION =
"1.1.0.beta2"
RB_EXT =
".rb"
RB_GLOB =
"*.rb"
PATH_SEPARATOR =
File::SEPARATOR
KEY_SEPARATOR =
"."
WORD_REGEX =
/\w+/

Class Method Summary collapse

Class Method Details

.loaderObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/dry/system.rb', line 9

def self.loader
  @loader ||= Zeitwerk::Loader.new.tap do |loader|
    root = File.expand_path("..", __dir__)
    loader.tag = "dry-system"
    loader.inflector = Zeitwerk::GemInflector.new("#{root}/dry-system.rb")
    loader.push_dir(root)
    loader.ignore(
      "#{root}/dry-system.rb",
      "#{root}/dry/system/{components,constants,errors,stubs,version}.rb"
    )
    loader.inflector.inflect("source_dsl" => "SourceDSL")
  end
end

.provider_sourcesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



56
57
58
# File 'lib/dry/system.rb', line 56

def self.provider_sources
  @provider_sources ||= ProviderSourceRegistry.new
end

.register_provider_source(name, group:, source: nil, provider_options: {}, &block) ⇒ Object

Registers a provider source, which can be used as the basis for other providers



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dry/system.rb', line 33

def self.register_provider_source(name, group:, source: nil, provider_options: {}, &block)
  if source && block
    raise ArgumentError, "You must supply only a `source:` option or a block, not both"
  end

  if source
    provider_sources.register(
      name: name,
      group: group,
      source: source,
      provider_options: provider_options
    )
  else
    provider_sources.register_from_block(
      name: name,
      group: group,
      provider_options: provider_options,
      &block
    )
  end
end

.register_provider_sources(path) ⇒ Object

Registers the provider sources in the files under the given path



26
27
28
# File 'lib/dry/system.rb', line 26

def self.register_provider_sources(path)
  provider_sources.load_sources(path)
end