Class: SmartCore::Container
- Inherits:
-
Object
- Object
- SmartCore::Container
show all
- Includes:
- Enumerable, DefinitionDSL
- Defined in:
- lib/smart_core/container.rb,
lib/smart_core/container/errors.rb,
lib/smart_core/container/version.rb,
lib/smart_core/container/definition_dsl.rb
Overview
rubocop:disable Style/StaticClass
Defined Under Namespace
Modules: DefinitionDSL, DependencyCompatability, DependencyResolver, Entities, KeyGuard, Mixin, RegistryBuilder
Classes: DependencyWatcher, Host, Registry, ResolvingError
Constant Summary
collapse
- NO_HOST_CONTAINER =
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.
nil
- NO_HOST_PATH =
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.
nil
- Error =
Class.new(SmartCore::Error)
- ArgumentError =
Class.new(SmartCore::ArgumentError)
- IncompatibleEntityNameError =
Class.new(ArgumentError)
- FrozenRegistryError =
Class.new(SmartCore::FrozenError)
- FetchError =
Class.new(Error)
- DependencyOverNamespaceOverlapError =
Class.new(Error)
- NamespaceOverDependencyOverlapError =
Class.new(Error)
- VERSION =
'0.11.0'
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#clear_observers(entity_path = nil) ⇒ void
(also: #clear_listeners)
-
#dependency?(dependency_path, memoized: nil) ⇒ Boolean
-
#each_dependency(yield_all: SmartCore::Container::Registry::DEFAULT_ITERATION_YIELD_BEHAVIOUR, &block) {|dependency_name, dependency_value| ... } ⇒ Enumerable
(also: #each, #each_pair)
-
#fetch(dependency_path) ⇒ Any
-
#freeze! ⇒ void
-
#frozen? ⇒ Boolean
-
#hash_tree(resolve_dependencies: false) ⇒ Hash<String|Symbol,SmartCore::Container::Entities::Base|Any>
(also: #to_h, #to_hash)
-
#initialize(host_container: NO_HOST_CONTAINER, host_path: NO_HOST_PATH) ⇒ void
constructor
-
#key?(key) ⇒ Boolean
-
#keys(all_variants: SmartCore::Container::Registry::DEFAULT_KEY_EXTRACTION_BEHAVIOUR) ⇒ Array<String>
-
#namespace(namespace_name, &dependencies_definition) ⇒ void
-
#namespace?(namespace_path) ⇒ Boolean
-
#observe(entity_path, &observer) {|entity_path, container| ... } ⇒ SmartCore::Container::DependencyWatcher::Observer
(also: #subscribe)
-
#register(dependency_name, memoize: SmartCore::Container::Registry::DEFAULT_MEMOIZATION_BEHAVIOR, &dependency_definition) ⇒ void
-
#reload! ⇒ void
-
#resolve(dependency_path) ⇒ Any
(also: #[])
-
#unobserve(observer) ⇒ Boolean
(also: #unsubscribe)
included
Constructor Details
#initialize(host_container: NO_HOST_CONTAINER, host_path: NO_HOST_PATH) ⇒ void
Instance Attribute Details
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.
71
72
73
|
# File 'lib/smart_core/container.rb', line 71
def host
@host
end
|
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.
65
66
67
|
# File 'lib/smart_core/container.rb', line 65
def registry
@registry
end
|
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.
77
78
79
|
# File 'lib/smart_core/container.rb', line 77
def watcher
@watcher
end
|
Class Method Details
.define(initial_container_klass = self, &container_definitions) ⇒ SmartCore::Container
32
33
34
35
36
37
38
39
40
|
# File 'lib/smart_core/container.rb', line 32
def define(initial_container_klass = self, &container_definitions)
unless initial_container_klass <= SmartCore::Container
raise(SmartCore::Container::ArgumentError, <<~ERROR_MESSAGE)
Base class should be a type of SmartCore::Container
ERROR_MESSAGE
end
Class.new(initial_container_klass, &container_definitions).new
end
|
Instance Method Details
#clear_observers(entity_path = nil) ⇒ void
Also known as:
clear_listeners
This method returns an undefined value.
279
280
281
|
# File 'lib/smart_core/container.rb', line 279
def clear_observers(entity_path = nil) @lock.write_sync { watcher.clear_listeners(entity_path) }
end
|
#dependency?(dependency_path, memoized: nil) ⇒ Boolean
212
213
214
|
# File 'lib/smart_core/container.rb', line 212
def dependency?(dependency_path, memoized: nil)
@lock.read_sync { DependencyResolver.dependency?(self, dependency_path, memoized: memoized) }
end
|
#each_dependency(yield_all: SmartCore::Container::Registry::DEFAULT_ITERATION_YIELD_BEHAVIOUR, &block) {|dependency_name, dependency_value| ... } ⇒ Enumerable
Also known as:
each, each_pair
#fetch(dependency_path) ⇒ Any
144
145
146
|
# File 'lib/smart_core/container.rb', line 144
def fetch(dependency_path)
@lock.read_sync { DependencyResolver.fetch(self, dependency_path) }
end
|
#freeze! ⇒ void
This method returns an undefined value.
153
154
155
|
# File 'lib/smart_core/container.rb', line 153
def freeze!
@lock.write_sync { registry.freeze! }
end
|
#frozen? ⇒ Boolean
162
163
164
|
# File 'lib/smart_core/container.rb', line 162
def frozen?
@lock.read_sync { registry.frozen? }
end
|
#hash_tree(resolve_dependencies: false) ⇒ Hash<String|Symbol,SmartCore::Container::Entities::Base|Any>
Also known as:
to_h, to_hash
241
242
243
|
# File 'lib/smart_core/container.rb', line 241
def hash_tree(resolve_dependencies: false)
@lock.read_sync { registry.hash_tree(resolve_dependencies: resolve_dependencies) }
end
|
#key?(key) ⇒ Boolean
191
192
193
|
# File 'lib/smart_core/container.rb', line 191
def key?(key)
@lock.read_sync { DependencyResolver.key?(self, key) }
end
|
#keys(all_variants: SmartCore::Container::Registry::DEFAULT_KEY_EXTRACTION_BEHAVIOUR) ⇒ Array<String>
#namespace(namespace_name, &dependencies_definition) ⇒ void
This method returns an undefined value.
120
121
122
123
124
125
|
# File 'lib/smart_core/container.rb', line 120
def namespace(namespace_name, &dependencies_definition)
@lock.write_sync do
registry.register_namespace(namespace_name, self, &dependencies_definition)
watcher.notify(namespace_name)
end
end
|
#namespace?(namespace_path) ⇒ Boolean
201
202
203
|
# File 'lib/smart_core/container.rb', line 201
def namespace?(namespace_path)
@lock.read_sync { DependencyResolver.namespace?(self, namespace_path) }
end
|
257
258
259
|
# File 'lib/smart_core/container.rb', line 257
def observe(entity_path, &observer) @lock.write_sync { watcher.watch(entity_path, &observer) }
end
|
#register(dependency_name, memoize: SmartCore::Container::Registry::DEFAULT_MEMOIZATION_BEHAVIOR, &dependency_definition) ⇒ void
This method returns an undefined value.
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/smart_core/container.rb', line 101
def register(
dependency_name,
memoize: SmartCore::Container::Registry::DEFAULT_MEMOIZATION_BEHAVIOR,
&dependency_definition
)
@lock.write_sync do
registry.register_dependency(dependency_name, memoize: memoize, &dependency_definition)
watcher.notify(dependency_name)
end
end
|
#reload! ⇒ void
This method returns an undefined value.
171
172
173
|
# File 'lib/smart_core/container.rb', line 171
def reload!
@lock.write_sync { build_registry! }
end
|
#resolve(dependency_path) ⇒ Any
Also known as:
[]
133
134
135
|
# File 'lib/smart_core/container.rb', line 133
def resolve(dependency_path)
@lock.read_sync { DependencyResolver.resolve(self, dependency_path) }
end
|
#unobserve(observer) ⇒ Boolean
Also known as:
unsubscribe
268
269
270
|
# File 'lib/smart_core/container.rb', line 268
def unobserve(observer)
@lock.write_sync { watcher.unwatch(observer) }
end
|