class Dry::System::Config::ComponentDirs
Public Class Methods
@api private
# File lib/dry/system/config/component_dirs.rb, line 88 def initialize @dirs = Concurrent::Map.new end
Public Instance Methods
Adds and configures a component dir
@param path [String] the path for the component dir, relative to the configured
container root
@yieldparam dir [ComponentDir] the component dir to configure
@return [ComponentDir] the added component dir
@example
component_dirs.add "lib" do |dir| dir.default_namespace = "my_app" end
@see ComponentDir
# File lib/dry/system/config/component_dirs.rb, line 113 def add(path) raise ComponentDirAlreadyAddedError, path if dirs.key?(path) dirs[path] = ComponentDir.new(path).tap do |dir| apply_defaults_to_dir(dir) yield dir if block_given? end end
Returns the added component dirs, with default settings applied
@return [Hash<String, ComponentDir>] the component dirs as a hash, keyed by path
# File lib/dry/system/config/component_dirs.rb, line 125 def dirs @dirs.each { |_, dir| apply_defaults_to_dir(dir) } end
Calls the given block once for each added component dir, passing the dir as an argument.
@yieldparam dir [ComponentDir] the yielded component dir
# File lib/dry/system/config/component_dirs.rb, line 140 def each(&block) to_a.each(&block) end
@api private
# File lib/dry/system/config/component_dirs.rb, line 93 def initialize_copy(source) super @dirs = source.dirs.dup end
Returns the added component dirs, with default settings applied
@return [Array<ComponentDir>]
# File lib/dry/system/config/component_dirs.rb, line 132 def to_a dirs.values end
Private Instance Methods
Apply default settings to a component dir. This is run every time the dirs are accessed to ensure defaults are applied regardless of when new component dirs are added. This method must be idempotent.
@return [void]
# File lib/dry/system/config/component_dirs.rb, line 151 def apply_defaults_to_dir(dir) dir.config.values.each do |key, _value| if configured?(key) && !dir.configured?(key) dir.public_send(:"#{key}=", public_send(key)) end end end
Returns true if a setting has been explicitly configured and is not returning just a default value.
This is used to determine which settings should be applied to added component dirs as additional defaults.
@api private
# File lib/dry/system/config/component_dirs.rb, line 166 def configured?(key) config._settings[key].input_defined? end
# File lib/dry/system/config/component_dirs.rb, line 170 def method_missing(name, *args, &block) if config.respond_to?(name) config.public_send(name, *args, &block) else super end end
# File lib/dry/system/config/component_dirs.rb, line 178 def respond_to_missing?(name, include_all = false) config.respond_to?(name) || super end