Class: Flows::Plugin::DependencyInjector::Dependency Private

Inherits:
Struct
  • Object
show all
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.

Since:

  • 0.4.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDependency

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.

Raises:

Since:

  • 0.4.0



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

#definitionObject

Returns the value of attribute definition

Returns:

  • (Object)

    the current value of definition



7
8
9
# File 'lib/flows/plugin/dependency_injector/dependency.rb', line 7

def definition
  @definition
end

#klassObject

Returns the value of attribute klass

Returns:

  • (Object)

    the current value of klass



7
8
9
# File 'lib/flows/plugin/dependency_injector/dependency.rb', line 7

def klass
  @klass
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



7
8
9
# File 'lib/flows/plugin/dependency_injector/dependency.rb', line 7

def name
  @name
end

#provided_valueObject

Returns the value of attribute provided_value

Returns:

  • (Object)

    the current value of provided_value



7
8
9
# File 'lib/flows/plugin/dependency_injector/dependency.rb', line 7

def provided_value
  @provided_value
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of 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.

Since:

  • 0.4.0



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