Class: SmartCore::Container::Entities::MemoizedDependency Private

Inherits:
Dependency
  • Object
show all
Defined in:
lib/smart_core/container/entities/memoized_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.

Since:

  • 0.2.0

Version:

  • 0.10.0

Instance Attribute Summary

Attributes inherited from Base

#external_name

Instance Method Summary collapse

Constructor Details

#initialize(dependency_name, dependency_definition) ⇒ void

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.

Parameters:

  • dependency_name (String)
  • dependency_definition (Proc)

Since:

  • 0.2.0

Version:

  • 0.10.0



15
16
17
18
# File 'lib/smart_core/container/entities/memoized_dependency.rb', line 15

def initialize(dependency_name, dependency_definition)
  super(dependency_name, dependency_definition)
  @lock = SmartCore::Engine::ReadWriteLock.new
end

Instance Method Details

#reveal(host_container = SmartCore::Container::NO_HOST_CONTAINER) ⇒ Any

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.

Parameters:

  • host_container (SmartCore::Container, NilClass) (defaults to: SmartCore::Container::NO_HOST_CONTAINER)

Returns:

  • (Any)

Since:

  • 0.2.0

Version:

  • 0.8.1



26
27
28
29
30
31
32
33
34
# File 'lib/smart_core/container/entities/memoized_dependency.rb', line 26

def reveal(host_container = SmartCore::Container::NO_HOST_CONTAINER)
  @lock.read_sync do
    unless instance_variable_defined?(:@revealed_dependency)
      @revealed_dependency = dependency_definition.call
    else
      @revealed_dependency
    end
  end
end