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.1.0

Defined Under Namespace

Classes: Route

Constant Summary collapse

PATH_PART_SEPARATOR =

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

Returns:

  • (String)

Since:

  • 0.4.0

'.'

Class Method Summary collapse

Class Method Details

.dependency?(container, dependency_path, memoized: nil) ⇒ Boolean

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:

  • container (SmartCore::Container)
  • dependency_path (String, Symbol)
  • memoized (Hash) (defaults to: nil)

    a customizable set of options

Options Hash (memoized:):

  • (NilClass, Boolean)

Returns:

  • (Boolean)

Since:

  • 0.5.0



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/smart_core/container/dependency_resolver.rb', line 62

def dependency?(container, dependency_path, memoized: nil)
  entity = extract(container, dependency_path)

  case
  when memoized == nil
    entity.is_a?(SmartCore::Container::Entities::Dependency)
  when !!memoized == true
    entity.is_a?(SmartCore::Container::Entities::MemoizedDependency)
  when !!memoized == false
    entity.is_a?(SmartCore::Container::Entities::Dependency) &&
      !entity.is_a?(SmartCore::Container::Entities::MemoizedDependency)
  end
rescue SmartCore::Container::ResolvingError
  false
end

.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.1.0

Version:

  • 0.8.1



26
27
28
# File 'lib/smart_core/container/dependency_resolver.rb', line 26

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

.key?(container, key) ⇒ Boolean

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:

  • (Boolean)

Since:

  • 0.5.0



36
37
38
39
40
41
# File 'lib/smart_core/container/dependency_resolver.rb', line 36

def key?(container, key)
  extract(container, key)
  true
rescue SmartCore::Container::ResolvingError
  false
end

.namespace?(container, namespace_path) ⇒ Boolean

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:

  • (Boolean)

Since:

  • 0.5.0



49
50
51
52
53
# File 'lib/smart_core/container/dependency_resolver.rb', line 49

def namespace?(container, namespace_path)
  extract(container, namespace_path).is_a?(SmartCore::Container::Entities::Namespace)
rescue SmartCore::Container::ResolvingError
  false
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.1.0

Version:

  • 0.8.1



91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/smart_core/container/dependency_resolver.rb', line 91

def resolve(container, dependency_path)
  entity = container
  host_container = container

  Route.build(dependency_path).each do |cursor|
    entity = entity.registry.resolve(cursor.current_path)
    prevent_ambiguous_resolving!(cursor, entity)
    entity = entity.reveal(host_container)
    host_container = entity.is_a?(SmartCore::Container) ? entity : nil
  end
  entity
rescue SmartCore::Container::ResolvingError => error
  process_resolving_error(dependency_path, error)
end