Class: Flows::Plugin::DependencyInjector::Dependency Private
- Inherits:
-
Struct
- Object
- Struct
- Flows::Plugin::DependencyInjector::Dependency
- Defined in:
- lib/flows/plugin/dependency_injector/dependency.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Resolves dependency on initialization and can inject it into class instance.
Instance Attribute Summary collapse
-
#definition ⇒ Object
Returns the value of attribute definition.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#name ⇒ Object
Returns the value of attribute name.
-
#provided_value ⇒ Object
Returns the value of attribute provided_value.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize ⇒ Dependency
constructor
private
A new instance of Dependency.
- #inject_to(instance) ⇒ Object private
Constructor Details
#initialize ⇒ Dependency
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 Dependency.
8 9 10 11 12 13 14 15 |
# File 'lib/flows/plugin/dependency_injector/dependency.rb', line 8 def initialize(*) super self.value = provided_value == NO_VALUE ? definition.default : provided_value type = definition.type raise UnexpectedDependencyTypeError.new(klass, name, value, type) if type != NO_TYPE && !(type === value) # rubocop:disable Style/CaseEquality end |
Instance Attribute Details
#definition ⇒ Object
Returns the value of attribute definition
7 8 9 |
# File 'lib/flows/plugin/dependency_injector/dependency.rb', line 7 def definition @definition end |
#klass ⇒ Object
Returns the value of attribute klass
7 8 9 |
# File 'lib/flows/plugin/dependency_injector/dependency.rb', line 7 def klass @klass end |
#name ⇒ Object
Returns the value of attribute name
7 8 9 |
# File 'lib/flows/plugin/dependency_injector/dependency.rb', line 7 def name @name end |
#provided_value ⇒ Object
Returns the value of attribute provided_value
7 8 9 |
# File 'lib/flows/plugin/dependency_injector/dependency.rb', line 7 def provided_value @provided_value end |
#value ⇒ Object
Returns the value of attribute value
7 8 9 |
# File 'lib/flows/plugin/dependency_injector/dependency.rb', line 7 def value @value end |
Instance Method Details
#inject_to(instance) ⇒ 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.
17 18 19 20 |
# File 'lib/flows/plugin/dependency_injector/dependency.rb', line 17 def inject_to(instance) value = self.value instance.define_singleton_method(name) { value } end |