Class: SmartCore::Injection::Locator::ContainerProxy Private

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_core/injection/locator/container_proxy.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.1.0

Instance Method Summary collapse

Constructor Details

#initialize(registered_containers, explicitly_passed_container) ⇒ 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:

Since:

  • 0.1.0



12
13
14
15
16
17
# File 'lib/smart_core/injection/locator/container_proxy.rb', line 12

def initialize(registered_containers, explicitly_passed_container)
  @registered_containers = registered_containers
  @explicitly_passed_container = explicitly_passed_container
  @observers = Hash.new { |h, k| h[k] = [] }
  registered_containers.listen_addings { |container| listen_changes(container) }
end

Instance Method Details

#observe(import_path, &observer) ⇒ 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.

This method returns an undefined value.

Parameters:

  • import_path (String)
  • observer (Block)

Since:

  • 0.1.0



53
54
55
56
57
58
59
# File 'lib/smart_core/injection/locator/container_proxy.rb', line 53

def observe(import_path, &observer)
  register_observer(import_path, observer)

  each_container do |container|
    container.observe(import_path) { |path, cntr| process_changement(cntr, path) }
  end
end

#resolve_dependency(dependency_path) ⇒ 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:

  • dependency_path (String)

Returns:

  • (Any)

Raises:

Since:

  • 0.1.0



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/smart_core/injection/locator/container_proxy.rb', line 27

def resolve_dependency(dependency_path)
  resolving_error = nil

  each_container do |container|
    begin # rubocop:disable Style/RedundantBegin
      return container.resolve(dependency_path)
    rescue SmartCore::Container::ResolvingError => error
      resolving_error = error
    end
  end

  unless resolving_error
    raise(SmartCore::Injection::NoRegisteredContainersError, <<~ERROR_MESSAGE)
      You haven't registered any containers for import.
    ERROR_MESSAGE
  else
    raise(resolving_error)
  end
end