Class: SmartCore::Container::Registry Private

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/smart_core/container/registry.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.

rubocop:disable Metrics/ClassLength

Since:

  • 0.1.0

Version:

  • 0.10.0

Constant Summary collapse

DEFAULT_MEMOIZATION_BEHAVIOR =

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:

  • (Boolean)

Since:

  • 0.3.0

false
DEFAULT_ITERATION_YIELD_BEHAVIOUR =

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:

  • (Boolean)

Since:

  • 0.4.0

false
DEFAULT_KEY_EXTRACTION_BEHAVIOUR =

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:

  • (Boolean)

Since:

  • 0.4.0

false

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializevoid

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

Version:

  • 0.10.0



40
41
42
43
# File 'lib/smart_core/container/registry.rb', line 40

def initialize
  @registry = {}
  @lock = SmartCore::Engine::ReadWriteLock.new
end

Instance Attribute Details

#registryHash<Symbol,SmartCore::Container::Entity> (readonly)

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:

  • (Hash<Symbol,SmartCore::Container::Entity>)

Since:

  • 0.1.0



33
34
35
# File 'lib/smart_core/container/registry.rb', line 33

def registry
  @registry
end

Instance Method Details

#each(&block) ⇒ Enumerable

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:

  • block (Block)

Returns:

  • (Enumerable)

Since:

  • 0.1.0

Version:

  • 0.10.0



107
108
109
# File 'lib/smart_core/container/registry.rb', line 107

def each(&block)
  @lock.read_sync { enumerate(&block) }
end

#each_dependency(root_dependency_name = nil, yield_all: DEFAULT_ITERATION_YIELD_BEHAVIOUR, &block) ⇒ Enumerable

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:

  • root_dependency_name (NilClass, String) (defaults to: nil)
  • block (Block)
  • yield_all (Hash) (defaults to: DEFAULT_ITERATION_YIELD_BEHAVIOUR)

    a customizable set of options

Options Hash (yield_all:):

  • (Boolean)

Returns:

  • (Enumerable)

Since:

  • 0.4.0

Version:

  • 0.10.0



119
120
121
122
123
124
125
# File 'lib/smart_core/container/registry.rb', line 119

def each_dependency(
  root_dependency_name = nil,
  yield_all: DEFAULT_ITERATION_YIELD_BEHAVIOUR,
  &block
)
  @lock.read_sync { iterate(root_dependency_name, yield_all: yield_all, &block) }
end

#freeze!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.

Since:

  • 0.1.0

Version:

  • 0.10.0



88
89
90
# File 'lib/smart_core/container/registry.rb', line 88

def freeze!
  @lock.write_sync { freeze_state! }
end

#frozen?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.

Returns:

  • (Boolean)

Since:

  • 0.1.0

Version:

  • 0.10.0



97
98
99
# File 'lib/smart_core/container/registry.rb', line 97

def frozen?
  @lock.read_sync { state_frozen? }
end

#hash_tree(resolve_dependencies: false) ⇒ Hash<String|Symbol,SmartCore::Container::Entities::Base|Any> Also known as: to_h, to_hash

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:

Since:

  • 0.1.0

Version:

  • 0.10.0



142
143
144
# File 'lib/smart_core/container/registry.rb', line 142

def hash_tree(resolve_dependencies: false)
  @lock.read_sync { build_hash_tree(resolve_dependencies: resolve_dependencies) }
end

#keys(all_variants: DEFAULT_KEY_EXTRACTION_BEHAVIOUR) ⇒ Array<String>

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:

  • all_variants (Hash) (defaults to: DEFAULT_KEY_EXTRACTION_BEHAVIOUR)

    a customizable set of options

Options Hash (all_variants:):

  • (Boolean)

Returns:

  • (Array<String>)

Since:

  • 0.4.0

Version:

  • 0.10.0



133
134
135
# File 'lib/smart_core/container/registry.rb', line 133

def keys(all_variants: DEFAULT_KEY_EXTRACTION_BEHAVIOUR)
  @lock.read_sync { extract_keys(all_variants: all_variants) }
end

#register_dependency(name, memoize: DEFAULT_MEMOIZATION_BEHAVIOR, &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.

This method returns an undefined value.

Parameters:

  • name (String, Symbol)
  • memoize (Boolean) (defaults to: DEFAULT_MEMOIZATION_BEHAVIOR)
  • dependency_definition (Block)

Since:

  • 0.1.0

Version:

  • 0.10.0



63
64
65
# File 'lib/smart_core/container/registry.rb', line 63

def register_dependency(name, memoize: DEFAULT_MEMOIZATION_BEHAVIOR, &dependency_definition)
  @lock.write_sync { add_dependency(name, dependency_definition, memoize) }
end

#register_namespace(name, host_container = SmartCore::Container::NO_HOST_CONTAINER, &dependencies_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.

This method returns an undefined value.

Parameters:

  • name (String, Symbol)
  • host_container (NilClasss, SmartCore::Container) (defaults to: SmartCore::Container::NO_HOST_CONTAINER)
  • dependencies_definition (Block)

Since:

  • 0.1.0

Version:

  • 0.10.0



75
76
77
78
79
80
81
# File 'lib/smart_core/container/registry.rb', line 75

def register_namespace(
  name,
  host_container = SmartCore::Container::NO_HOST_CONTAINER,
  &dependencies_definition
)
  @lock.write_sync { add_namespace(name, host_container, dependencies_definition) }
end

#resolve(entity_path) ⇒ SmartCore::Container::Entity

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:

  • entity_path (String, Symbol)

Returns:

  • (SmartCore::Container::Entity)

Since:

  • 0.1.0

Version:

  • 0.10.0



51
52
53
# File 'lib/smart_core/container/registry.rb', line 51

def resolve(entity_path)
  @lock.read_sync { fetch_entity(entity_path) }
end