Class: Dry::System::Config::ComponentDir
- Inherits:
-
Object
- Object
- Dry::System::Config::ComponentDir
- Includes:
- Configurable
- Defined in:
- lib/dry/system/config/component_dir.rb
Instance Attribute Summary collapse
-
#path ⇒ String
readonly
Returns the component dir path, relative to the configured container root.
Settings collapse
-
#add_to_load_path ⇒ Boolean
Returns the configured value.
-
#add_to_load_path=(policy) ⇒ Boolean
Sets whether the dir should be added to the ‘$LOAD_PATH` after the container is configured.
-
#auto_register ⇒ Boolean, Proc
Returns the configured auto-registration policy.
-
#auto_register=(policy) ⇒ Boolean, Proc
Sets the auto-registration policy for the component dir.
-
#instance ⇒ Proc?
Returns the configured instance proc.
-
#instance=(instance_proc) ⇒ Proc
Sets a proc used to return the instance of any component within the component dir.
-
#loader ⇒ #call
Returns the configured loader.
-
#loader=(loader) ⇒ #call
Sets the loader to use when registering components from the dir in the container.
-
#memoize ⇒ Boolean, Proc
Returns the configured memoization policy.
-
#memoize=(policy) ⇒ Boolean, Proc
Sets whether to memoize components from the dir when registered in the container.
-
#namespaces ⇒ Namespaces
Returns the configured namespaces for the component dir.
Instance Method Summary collapse
- #auto_register? ⇒ Boolean private
-
#initialize(path) {|_self| ... } ⇒ ComponentDir
constructor
A new instance of ComponentDir.
Constructor Details
#initialize(path) {|_self| ... } ⇒ ComponentDir
Returns a new instance of ComponentDir.
201 202 203 204 205 |
# File 'lib/dry/system/config/component_dir.rb', line 201 def initialize(path) super() @path = path yield self if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (private)
214 215 216 217 218 219 220 |
# File 'lib/dry/system/config/component_dir.rb', line 214 def method_missing(name, *args, &block) if config.respond_to?(name) config.public_send(name, *args, &block) else super end end |
Instance Attribute Details
#path ⇒ String (readonly)
Returns the component dir path, relative to the configured container root
198 199 200 |
# File 'lib/dry/system/config/component_dir.rb', line 198 def path @path end |
Instance Method Details
#add_to_load_path ⇒ Boolean
Returns the configured value.
191 |
# File 'lib/dry/system/config/component_dir.rb', line 191 setting :add_to_load_path, default: true |
#add_to_load_path=(policy) ⇒ Boolean
Sets whether the dir should be added to the ‘$LOAD_PATH` after the container is configured.
Defaults to ‘true`. This may need to be set to `false` when using a class autoloading system.
191 |
# File 'lib/dry/system/config/component_dir.rb', line 191 setting :add_to_load_path, default: true |
#auto_register ⇒ Boolean, Proc
Returns the configured auto-registration policy.
47 |
# File 'lib/dry/system/config/component_dir.rb', line 47 setting :auto_register, default: true |
#auto_register=(policy) ⇒ Boolean, Proc
Sets the auto-registration policy for the component dir.
This may be a simple boolean to enable or disable auto-registration for all components, or a proc accepting a Dry::System::Component and returning a boolean to configure auto-registration on a per-component basis
Defaults to ‘true`.
47 |
# File 'lib/dry/system/config/component_dir.rb', line 47 setting :auto_register, default: true |
#auto_register? ⇒ Boolean
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.
208 209 210 |
# File 'lib/dry/system/config/component_dir.rb', line 208 def auto_register? !!config.auto_register end |
#instance ⇒ Proc?
Returns the configured instance proc.
90 |
# File 'lib/dry/system/config/component_dir.rb', line 90 setting :instance |
#instance=(instance_proc) ⇒ Proc
Sets a proc used to return the instance of any component within the component dir.
This proc should accept a Dry::System::Component and return the object to serve as the component’s instance.
When you provide an instance proc, it will be used in preference to the #loader (either the default loader or an explicitly configured one). Provide an instance proc when you want a simple way to customize the instance for certain components. For complete control, provide a replacement loader via #loader=.
Defaults to ‘nil`.
90 |
# File 'lib/dry/system/config/component_dir.rb', line 90 setting :instance |
#loader ⇒ #call
Returns the configured loader.
118 |
# File 'lib/dry/system/config/component_dir.rb', line 118 setting :loader, default: Dry::System::Loader |
#loader=(loader) ⇒ #call
Sets the loader to use when registering components from the dir in the container.
Defaults to ‘Dry::System::Loader`.
When using an autoloader like Zeitwerk, consider using ‘Dry::System::Loader::Autoloading`
118 |
# File 'lib/dry/system/config/component_dir.rb', line 118 setting :loader, default: Dry::System::Loader |
#memoize ⇒ Boolean, Proc
Returns the configured memoization policy.
154 |
# File 'lib/dry/system/config/component_dir.rb', line 154 setting :memoize, default: false |
#memoize=(policy) ⇒ Boolean, Proc
Sets whether to memoize components from the dir when registered in the container.
This may be a simple boolean to enable or disable memoization for all components, or a proc accepting a ‘Dry::Sytem::Component` and returning a boolean to configure memoization on a per-component basis
Defaults to ‘false`.
154 |
# File 'lib/dry/system/config/component_dir.rb', line 154 setting :memoize, default: false |
#namespaces ⇒ Namespaces
Returns the configured namespaces for the component dir.
Allows namespaces to added on the returned object via Namespaces#add.
166 |
# File 'lib/dry/system/config/component_dir.rb', line 166 setting :namespaces, default: Namespaces.new, cloneable: true |