Module: SmartCore::Container::DependencyResolver Private

Defined in:
lib/smart_core/container/dependency_resolver.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Since:

  • 0.7.0

Defined Under Namespace

Classes: Route

Class Method Summary collapse

Class Method Details

.fetch(container, dependency_path) ⇒ SmartCore::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:

Returns:

See Also:

Since:

  • 0.8.0



19
20
21
# File 'lib/smart_core/container/dependency_resolver.rb', line 19

def fetch(container, dependency_path)
  container.registry.resolve(dependency_path).reveal
end

.resolve(container, dependency_path) ⇒ SmartCore::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:

Returns:

Raises:

See Also:

Since:

  • 0.7.0

Version:

  • 0.8.0



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/smart_core/container/dependency_resolver.rb', line 36

def resolve(container, dependency_path)
  entity = container

  Route.build(dependency_path).each do |cursor|
    entity = entity.registry.resolve(cursor.current_path)
    if cursor.last? && entity.is_a?(SmartCore::Container::Entities::Namespace)
      # rubocop:enable Metrics/LineLength
      raise(SmartCore::Container::ResolvingError.new(<<~MESSAGE, path_part: cursor.current_path))
        Trying to resolve a namespace as a dependency
      MESSAGE
      # rubocop:disable Metrics/LineLength
    end
    if !cursor.last? && entity.is_a?(SmartCore::Container::Entities::Dependency)
      # rubocop:enable Metrics/LineLength
      raise(SmartCore::Container::ResolvingError.new(<<~MESSAGE, path_part: cursor.current_path))
        Trying to resolve nonexistent dependency
      MESSAGE
      # rubocop:disable Metrics/LineLength
    end
    entity = entity.reveal
  end

  entity
rescue SmartCore::Container::ResolvingError => error
  full_dependency_path = Route.build_path(dependency_path, error.path_part)
  raise(SmartCore::Container::ResolvingError.new(<<~MESSAGE, path_part: full_dependency_path))
    #{error.message} (incorrect path: "#{full_dependency_path}")
  MESSAGE
end