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
106 107 108 109 |
# File 'lib/dry/system/config/component_dirs.rb', line 106 def initialize @dirs = {} @defaults = ComponentDir.new(nil) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (private)
275 276 277 278 279 280 281 |
# File 'lib/dry/system/config/component_dirs.rb', line 275 def method_missing(name, *args, &block) if defaults.respond_to?(name) defaults.public_send(name, *args, &block) 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
101 102 103 |
# File 'lib/dry/system/config/component_dirs.rb', line 101 def defaults @defaults end |
Instance Method Details
#add(path) {|dir| ... } ⇒ ComponentDir #add(dir) ⇒ ComponentDir
164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/dry/system/config/component_dirs.rb', line 164 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 79
|
#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 79
|
#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
185 186 187 |
# File 'lib/dry/system/config/component_dirs.rb', line 185 def delete(path) dirs.delete(path) end |
#dir(path) {|dir| ... } ⇒ ComponentDir Also known as: []
Returns and optionally yields a previously added component dir
125 126 127 128 129 130 131 |
# File 'lib/dry/system/config/component_dirs.rb', line 125 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.
224 225 226 |
# File 'lib/dry/system/config/component_dirs.rb', line 224 def each(&block) to_a.each(&block) 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.
112 113 114 115 |
# File 'lib/dry/system/config/component_dirs.rb', line 112 def initialize_copy(source) @dirs = source.dirs.map { |path, dir| [path, dir.dup] }.to_h @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
203 204 205 |
# File 'lib/dry/system/config/component_dirs.rb', line 203 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 69
|
#paths ⇒ Array<String>
Returns the paths of the component dirs
194 195 196 |
# File 'lib/dry/system/config/component_dirs.rb', line 194 def paths dirs.keys end |
#to_a ⇒ Array<ComponentDir>
Returns the added component dirs, with default settings applied
213 214 215 216 |
# File 'lib/dry/system/config/component_dirs.rb', line 213 def to_a dirs.each { |_, dir| apply_defaults_to_dir(dir) } dirs.values end |