Class: Dry::System::Config::ComponentDirs
- Inherits:
-
Object
- Object
- Dry::System::Config::ComponentDirs
- Defined in:
- lib/dry/system/config/component_dirs.rb
Overview
The configured component dirs for a container
Instance Attribute Summary collapse
-
#defaults ⇒ Object
readonly
private
A ComponentDir for configuring the default values to apply to all added component dirs.
Settings collapse
-
#add_to_load_path ⇒ Object
Returns the configured default ‘add_to_load_path`.
-
#add_to_load_path=(value) ⇒ Object
Sets a default ‘add_to_load_path` value for all added component dirs.
-
#auto_register ⇒ Object
Returns the configured default ‘instance`.
-
#auto_register=(value) ⇒ Object
Sets a default ‘auto_register` for all added component dirs.
-
#instance=(value) ⇒ Object
Sets a default ‘instance` for all added component dirs.
-
#loader ⇒ Object
Returns the configured default ‘loader`.
-
#loader=(value) ⇒ Object
Sets a default ‘loader` value for all added component dirs.
-
#memoize ⇒ Object
Returns the configured default ‘memoize`.
-
#memoize=(value) ⇒ Object
Sets a default ‘memoize` value for all added component dirs.
-
#namespaces ⇒ Namespaces
Returns the default configured namespaces for all added component dirs.
Instance Method Summary collapse
- #add(path_or_dir) ⇒ Object
-
#delete(path) ⇒ ComponentDir
Deletes and returns a previously added component dir.
-
#dir(path) {|dir| ... } ⇒ ComponentDir
(also: #[])
Returns and optionally yields a previously added component dir.
-
#each {|dir| ... } ⇒ Object
Calls the given block once for each added component dir, passing the dir as an argument.
-
#initialize ⇒ ComponentDirs
constructor
private
Creates a new component dirs.
- #initialize_copy(source) ⇒ Object private
-
#length ⇒ Integer
(also: #size)
Returns the count of component dirs.
-
#paths ⇒ Array<String>
Returns the paths of the component dirs.
-
#to_a ⇒ Array<ComponentDir>
Returns the added component dirs, with default settings applied.
Constructor Details
#initialize ⇒ ComponentDirs
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.
Creates a new component dirs
102 103 104 105 |
# File 'lib/dry/system/config/component_dirs.rb', line 102 def initialize @dirs = {} @defaults = ComponentDir.new(nil) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object (private)
271 272 273 274 275 276 277 |
# File 'lib/dry/system/config/component_dirs.rb', line 271 def method_missing(name, ...) if defaults.respond_to?(name) defaults.public_send(name, ...) else super end end |
Instance Attribute Details
#defaults ⇒ Object (readonly)
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.
A ComponentDir for configuring the default values to apply to all added component dirs
97 98 99 |
# File 'lib/dry/system/config/component_dirs.rb', line 97 def defaults @defaults end |
Instance Method Details
#add(path) {|dir| ... } ⇒ ComponentDir #add(dir) ⇒ ComponentDir
160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/dry/system/config/component_dirs.rb', line 160 def add(path_or_dir) path, dir_to_add = path_and_dir(path_or_dir) raise ComponentDirAlreadyAddedError, path if dirs.key?(path) dirs[path] = dir_to_add.tap do |dir| # Defaults must be applied after yielding, since the dir is being newly added, # and must have its configuration fully in place before we can know which # defaults to apply yield dir if path_or_dir == path && block_given? apply_defaults_to_dir(dir) end end |
#add_to_load_path ⇒ Object
Returns the configured default ‘add_to_load_path`
|
|
# File 'lib/dry/system/config/component_dirs.rb', line 77
|
#add_to_load_path=(value) ⇒ Object
Sets a default ‘add_to_load_path` value for all added component dirs
|
|
# File 'lib/dry/system/config/component_dirs.rb', line 77
|
#auto_register ⇒ Object
Returns the configured default ‘instance`
|
|
# File 'lib/dry/system/config/component_dirs.rb', line 15
|
#auto_register=(value) ⇒ Object
Sets a default ‘auto_register` for all added component dirs
|
|
# File 'lib/dry/system/config/component_dirs.rb', line 15
|
#delete(path) ⇒ ComponentDir
Deletes and returns a previously added component dir
181 182 183 |
# File 'lib/dry/system/config/component_dirs.rb', line 181 def delete(path) dirs.delete(path) end |
#dir(path) {|dir| ... } ⇒ ComponentDir Also known as: []
Returns and optionally yields a previously added component dir
121 122 123 124 125 126 127 |
# File 'lib/dry/system/config/component_dirs.rb', line 121 def dir(path) dirs[path].tap do |dir| # Defaults can be (re-)applied first, since the dir has already been added apply_defaults_to_dir(dir) if dir yield dir if block_given? end end |
#each {|dir| ... } ⇒ Object
Calls the given block once for each added component dir, passing the dir as an argument.
220 221 222 |
# File 'lib/dry/system/config/component_dirs.rb', line 220 def each(&) to_a.each(&) end |
#initialize_copy(source) ⇒ Object
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.
108 109 110 111 |
# File 'lib/dry/system/config/component_dirs.rb', line 108 def initialize_copy(source) @dirs = source.dirs.transform_values(&:dup) @defaults = source.defaults.dup end |
#instance=(value) ⇒ Object
Sets a default ‘instance` for all added component dirs
|
|
# File 'lib/dry/system/config/component_dirs.rb', line 28
|
#length ⇒ Integer Also known as: size
Returns the count of component dirs
199 200 201 |
# File 'lib/dry/system/config/component_dirs.rb', line 199 def length dirs.length end |
#loader ⇒ Object
Returns the configured default ‘loader`
|
|
# File 'lib/dry/system/config/component_dirs.rb', line 41
|
#loader=(value) ⇒ Object
Sets a default ‘loader` value for all added component dirs
|
|
# File 'lib/dry/system/config/component_dirs.rb', line 41
|
#memoize ⇒ Object
Returns the configured default ‘memoize`
|
|
# File 'lib/dry/system/config/component_dirs.rb', line 54
|
#memoize=(value) ⇒ Object
Sets a default ‘memoize` value for all added component dirs
|
|
# File 'lib/dry/system/config/component_dirs.rb', line 54
|
#namespaces ⇒ Namespaces
Returns the default configured namespaces for all added component dirs
Allows namespaces to added on the returned object via Namespaces#add.
|
|
# File 'lib/dry/system/config/component_dirs.rb', line 67
|
#paths ⇒ Array<String>
Returns the paths of the component dirs
190 191 192 |
# File 'lib/dry/system/config/component_dirs.rb', line 190 def paths dirs.keys end |
#to_a ⇒ Array<ComponentDir>
Returns the added component dirs, with default settings applied
209 210 211 212 |
# File 'lib/dry/system/config/component_dirs.rb', line 209 def to_a dirs.each { |_, dir| apply_defaults_to_dir(dir) } dirs.values end |