Class: Dry::System::Loader
- Inherits:
-
Object
- Object
- Dry::System::Loader
- Defined in:
- lib/dry/system/loader.rb
Overview
Default component loader implementation
This class is configured by default for every System::Container. You can provide your own and use it in your containers too.
Instance Attribute Summary collapse
- #inflector ⇒ Object readonly
- #path ⇒ Object readonly
Instance Method Summary collapse
-
#call(*args) ⇒ Object
Returns component’s instance.
-
#constant ⇒ Class
Return component’s class constant.
-
#initialize(path, inflector = Dry::Inflector.new) ⇒ Loader
constructor
private
A new instance of Loader.
Constructor Details
#initialize(path, inflector = Dry::Inflector.new) ⇒ Loader
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.
Returns a new instance of Loader.
35 36 37 38 |
# File 'lib/dry/system/loader.rb', line 35 def initialize(path, inflector = Dry::Inflector.new) @path = path @inflector = inflector end |
Instance Attribute Details
#inflector ⇒ Object (readonly)
32 33 34 |
# File 'lib/dry/system/loader.rb', line 32 def inflector @inflector end |
#path ⇒ Object (readonly)
28 29 30 |
# File 'lib/dry/system/loader.rb', line 28 def path @path end |
Instance Method Details
#call(*args) ⇒ Object
Returns component’s instance
Provided optional args are passed to object’s constructor
49 50 51 52 53 54 55 |
# File 'lib/dry/system/loader.rb', line 49 def call(*args) if singleton?(constant) constant.instance(*args) else constant.new(*args) end end |
#constant ⇒ Class
Return component’s class constant
62 63 64 |
# File 'lib/dry/system/loader.rb', line 62 def constant inflector.constantize(inflector.camelize(path)) end |