smart_container 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +1 -1
- data/README.md +15 -4
- data/lib/smart_core/container.rb +34 -10
- data/lib/smart_core/container/dependency_resolver.rb +11 -3
- data/lib/smart_core/container/dependency_watcher.rb +3 -1
- data/lib/smart_core/container/entities/dependency.rb +3 -1
- data/lib/smart_core/container/entities/dependency_builder.rb +27 -59
- data/lib/smart_core/container/entities/memoized_dependency.rb +3 -1
- data/lib/smart_core/container/entities/namespace.rb +22 -5
- data/lib/smart_core/container/entities/namespace_builder.rb +14 -34
- data/lib/smart_core/container/host.rb +77 -0
- data/lib/smart_core/container/registry.rb +13 -4
- data/lib/smart_core/container/version.rb +2 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbae5c2d40dc40e3114d685c1f13d6cbfb7003a1c8fda862ef5dbcfa432cf5cd
|
4
|
+
data.tar.gz: dd288fa47167c0da4e2aae656478170d0dd78b142eef52a351c461ddbc92bf29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27129a91c84f8aad432c5462c2d3a921284b2b8e3b1fb4b0a215295f6f88d94063946cc24f2d065f6da9ba6e64baf421f2a192b68fa63ebda879a81715e2c88f
|
7
|
+
data.tar.gz: 5e6839adcfe1e3c31513b622fc3e46aab37ab3ec35a992c8a3b9c7ff029c976dbf331619d3df20da7ffe3d712a8839f04ac83f3055f9e2426869e9b9ecf556f6
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [0.8.1] - 2020-07-09
|
5
|
+
### Changed
|
6
|
+
- *Core*
|
7
|
+
- refactored `SmartCore::Container::Entities::NamespaceBuilder` and `SmartCore::Container::Entities::DependencyBuilder`
|
8
|
+
(from stateful-based logic on instances to stateless-based logic on modules);
|
9
|
+
|
10
|
+
### Fixed
|
11
|
+
- Subscription to the nested dependency changement doesn't work
|
12
|
+
(incomplete nested dependency path in watcher notification);
|
13
|
+
|
4
14
|
## [0.8.0] - 2020-07-08
|
5
15
|
### Added
|
6
16
|
- An ability to observe dependency re-registrations:
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -35,7 +35,7 @@ require 'smart_core/container'
|
|
35
35
|
- [reloading](#reloading)
|
36
36
|
- [hash tree](#hash-tree)
|
37
37
|
- [explicit class definition](#explicit-class-definition)
|
38
|
-
- [dependency
|
38
|
+
- [subscribe to dependency changements](#subscribe-to-dependency-changements)
|
39
39
|
- [Roadmap](#roadmap)
|
40
40
|
|
41
41
|
---
|
@@ -257,7 +257,7 @@ AppContainer['db_driver'] # => Sequel (AppContainer dependency)
|
|
257
257
|
|
258
258
|
---
|
259
259
|
|
260
|
-
#### dependency
|
260
|
+
#### subscribe to dependency changements
|
261
261
|
|
262
262
|
- features and limitations:
|
263
263
|
- you can subscribe only on container instances (on container instance changements);
|
@@ -292,13 +292,13 @@ end
|
|
292
292
|
```
|
293
293
|
|
294
294
|
```ruby
|
295
|
-
container.
|
295
|
+
container.fetch('database').register('stats') = 'kek' # => invokes entity_observer and outputs "changed! => 'kek'"
|
296
296
|
container.namespace('database') {} # => invoks namespace_observer and outputs "changed => 'database'"
|
297
297
|
|
298
298
|
container.unobserve(observer) # unsubscribe entity_observer from dependency changement observing;
|
299
299
|
container.clear_observers # unsubscribe all observers
|
300
300
|
|
301
|
-
container.
|
301
|
+
container.fetch('database').register('stats') = 'pek' # no one to listen this changement... :)
|
302
302
|
container.namespace('database') {} # no one to listen this changement... :)
|
303
303
|
```
|
304
304
|
|
@@ -306,6 +306,17 @@ container.namespace('database') {} # no one to listen this changement... :)
|
|
306
306
|
|
307
307
|
## Roadmap
|
308
308
|
|
309
|
+
- convinient way to rebind registered dependnecies:
|
310
|
+
|
311
|
+
```ruby
|
312
|
+
# PoC
|
313
|
+
|
314
|
+
container['dependency.path'] = 'pek' # simplest instant dependency registration without memoization
|
315
|
+
# --- or/and ---
|
316
|
+
container.rebind('dependency.path', memoize: true/false) { 'pek' } # bind with dynamic dependency registration
|
317
|
+
container.rebind('dependency.path', memoize: true/false, 'pek') # bind with instant dependency registration
|
318
|
+
```
|
319
|
+
|
309
320
|
- pattern-based pathes in dependency changement observing;
|
310
321
|
|
311
322
|
```ruby
|
data/lib/smart_core/container.rb
CHANGED
@@ -19,6 +19,7 @@ module SmartCore
|
|
19
19
|
require_relative 'container/registry_builder'
|
20
20
|
require_relative 'container/dependency_resolver'
|
21
21
|
require_relative 'container/dependency_watcher'
|
22
|
+
require_relative 'container/host'
|
22
23
|
require_relative 'container/mixin'
|
23
24
|
|
24
25
|
class << self
|
@@ -45,18 +46,48 @@ module SmartCore
|
|
45
46
|
# @since 0.1.0
|
46
47
|
include DefinitionDSL
|
47
48
|
|
49
|
+
# @return [NilClass]
|
50
|
+
#
|
51
|
+
# @api private
|
52
|
+
# @since 0.8.1
|
53
|
+
NO_HOST_CONTAINER = nil
|
54
|
+
|
55
|
+
# @return [NilClass]
|
56
|
+
#
|
57
|
+
# @api private
|
58
|
+
# @since 0.8.1
|
59
|
+
NO_HOST_PATH = nil
|
60
|
+
|
48
61
|
# @return [SmartCore::Container::Registry]
|
49
62
|
#
|
50
63
|
# @api private
|
51
64
|
# @since 0.1.0
|
52
65
|
attr_reader :registry
|
53
66
|
|
67
|
+
# @return [SmartCore::Container::Host]
|
68
|
+
#
|
69
|
+
# @api private
|
70
|
+
# @since 0.8.1
|
71
|
+
attr_reader :host
|
72
|
+
|
73
|
+
# @return [SmartCore::Container::DependencyWatcher]
|
74
|
+
#
|
75
|
+
# @api private
|
76
|
+
# @since 0.8.0
|
77
|
+
attr_reader :watcher
|
78
|
+
|
79
|
+
# @option host_container [SmartCore::Container, NilClass]
|
80
|
+
# @option host_path [String, NilClass]
|
54
81
|
# @return [void]
|
55
82
|
#
|
56
83
|
# @api public
|
57
84
|
# @since 0.1.0
|
58
|
-
|
85
|
+
# @version 0.8.1
|
86
|
+
def initialize(host_container: NO_HOST_CONTAINER, host_path: NO_HOST_PATH)
|
87
|
+
@host = SmartCore::Container::Host.build(host_container, host_path)
|
59
88
|
build_registry!
|
89
|
+
@watcher = SmartCore::Container::DependencyWatcher.new(self)
|
90
|
+
@host_path = host_path
|
60
91
|
@access_lock = ArbitraryLock.new
|
61
92
|
end
|
62
93
|
|
@@ -87,7 +118,7 @@ module SmartCore
|
|
87
118
|
# @version 0.8.0
|
88
119
|
def namespace(namespace_name, &dependencies_definition)
|
89
120
|
thread_safe do
|
90
|
-
registry.register_namespace(namespace_name, &dependencies_definition)
|
121
|
+
registry.register_namespace(namespace_name, self, &dependencies_definition)
|
91
122
|
watcher.notify(namespace_name)
|
92
123
|
end
|
93
124
|
end
|
@@ -238,20 +269,13 @@ module SmartCore
|
|
238
269
|
|
239
270
|
private
|
240
271
|
|
241
|
-
# @return [SmartCore::Container::DependencyWatcher]
|
242
|
-
#
|
243
|
-
# @api private
|
244
|
-
# @since 0.8.0
|
245
|
-
attr_reader :watcher
|
246
|
-
|
247
272
|
# @return [void]
|
248
273
|
#
|
249
274
|
# @api private
|
250
275
|
# @since 0.1.0
|
251
|
-
# @version 0.8.
|
276
|
+
# @version 0.8.1
|
252
277
|
def build_registry!
|
253
278
|
@registry = RegistryBuilder.build(self)
|
254
|
-
@watcher = SmartCore::Container::DependencyWatcher.new(self)
|
255
279
|
end
|
256
280
|
|
257
281
|
# @param block [Block]
|
@@ -22,8 +22,9 @@ module SmartCore::Container::DependencyResolver
|
|
22
22
|
#
|
23
23
|
# @api private
|
24
24
|
# @since 0.1.0
|
25
|
+
# @version 0.8.1
|
25
26
|
def fetch(container, dependency_path)
|
26
|
-
container.registry.resolve(dependency_path).reveal
|
27
|
+
container.registry.resolve(dependency_path).reveal(container)
|
27
28
|
end
|
28
29
|
|
29
30
|
# @param container [SmartCore::Container]
|
@@ -86,12 +87,16 @@ module SmartCore::Container::DependencyResolver
|
|
86
87
|
#
|
87
88
|
# @api private
|
88
89
|
# @since 0.1.0
|
90
|
+
# @version 0.8.1
|
89
91
|
def resolve(container, dependency_path)
|
90
92
|
entity = container
|
93
|
+
host_container = container
|
94
|
+
|
91
95
|
Route.build(dependency_path).each do |cursor|
|
92
96
|
entity = entity.registry.resolve(cursor.current_path)
|
93
97
|
prevent_ambiguous_resolving!(cursor, entity)
|
94
|
-
entity = entity.reveal
|
98
|
+
entity = entity.reveal(host_container)
|
99
|
+
host_container = entity.is_a?(SmartCore::Container) ? entity : nil
|
95
100
|
end
|
96
101
|
entity
|
97
102
|
rescue SmartCore::Container::ResolvingError => error
|
@@ -106,14 +111,17 @@ module SmartCore::Container::DependencyResolver
|
|
106
111
|
#
|
107
112
|
# @api private
|
108
113
|
# @since 0.5.0
|
114
|
+
# @version 0.8.1
|
109
115
|
def extract(container, entity_path)
|
110
116
|
resolved_entity = container
|
111
117
|
extracted_entity = container
|
118
|
+
host_container = container
|
112
119
|
|
113
120
|
Route.build(entity_path).each do |cursor|
|
114
121
|
resolved_entity = resolved_entity.registry.resolve(cursor.current_path)
|
115
122
|
extracted_entity = resolved_entity
|
116
|
-
resolved_entity = resolved_entity.reveal
|
123
|
+
resolved_entity = resolved_entity.reveal(host_container)
|
124
|
+
host_container = resolved_entity.is_a?(SmartCore::Container) ? resolved_entity : nil
|
117
125
|
end
|
118
126
|
|
119
127
|
extracted_entity
|
@@ -12,7 +12,7 @@ class SmartCore::Container::DependencyWatcher
|
|
12
12
|
# @since 0.8.0
|
13
13
|
def initialize(container)
|
14
14
|
@container = container
|
15
|
-
@observers = Hash.new { |
|
15
|
+
@observers = Hash.new { |h, k| h[k] = [] }
|
16
16
|
@access_lock = SmartCore::Container::ArbitraryLock.new
|
17
17
|
end
|
18
18
|
|
@@ -72,9 +72,11 @@ class SmartCore::Container::DependencyWatcher
|
|
72
72
|
#
|
73
73
|
# @api private
|
74
74
|
# @since 0.8.0
|
75
|
+
# @version 0.8.1
|
75
76
|
def notify_listeners(entity_path)
|
76
77
|
entity_path = indifferently_accessable_path(entity_path)
|
77
78
|
observers.fetch(entity_path).each(&:notify!) if observers.key?(entity_path)
|
79
|
+
container.host.notify_about_nested_changement(entity_path)
|
78
80
|
end
|
79
81
|
|
80
82
|
# @param entity_path [String, Symbol]
|
@@ -20,11 +20,13 @@ class SmartCore::Container::Entities::Dependency < SmartCore::Container::Entitie
|
|
20
20
|
@dependency_definition = dependency_definition
|
21
21
|
end
|
22
22
|
|
23
|
+
# @param host_container [SmartCore::Container, NilClass]
|
23
24
|
# @return [Any]
|
24
25
|
#
|
25
26
|
# @api private
|
26
27
|
# @since 0.1.0
|
27
|
-
|
28
|
+
# @version 0.8.1
|
29
|
+
def reveal(host_container = SmartCore::Container::NO_HOST_CONTAINER)
|
28
30
|
dependency_definition.call
|
29
31
|
end
|
30
32
|
|
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
# @api private
|
4
4
|
# @since 0.1.0
|
5
|
-
|
5
|
+
# @version 0.8.1
|
6
|
+
module SmartCore::Container::Entities::DependencyBuilder
|
6
7
|
class << self
|
7
8
|
# @param dependency_name [String]
|
8
9
|
# @param dependency_definition [Proc]
|
@@ -11,68 +12,35 @@ class SmartCore::Container::Entities::DependencyBuilder
|
|
11
12
|
#
|
12
13
|
# @api private
|
13
14
|
# @since 0.1.0
|
14
|
-
# @version 0.
|
15
|
+
# @version 0.8.1
|
15
16
|
def build(dependency_name, dependency_definition, memoize)
|
16
|
-
|
17
|
+
if memoize
|
18
|
+
build_memoized_dependency(dependency_name, dependency_definition)
|
19
|
+
else
|
20
|
+
build_original_dependency(dependency_name, dependency_definition)
|
21
|
+
end
|
17
22
|
end
|
18
|
-
end
|
19
|
-
|
20
|
-
# @param dependency_name [String]
|
21
|
-
# @param dependency_definition [Proc]
|
22
|
-
# @param memoize [Boolean]
|
23
|
-
# @return [void]
|
24
|
-
#
|
25
|
-
# @api private
|
26
|
-
# @since 0.1.0
|
27
|
-
# @version 0.2.0
|
28
|
-
def initialize(dependency_name, dependency_definition, memoize)
|
29
|
-
@dependency_name = dependency_name
|
30
|
-
@dependency_definition = dependency_definition
|
31
|
-
@memoize = memoize
|
32
|
-
end
|
33
|
-
|
34
|
-
# @return [SmartCore::Container::Entities::Dependency]
|
35
|
-
#
|
36
|
-
# @api private
|
37
|
-
# @since 0.1.0
|
38
|
-
# @version 0.2.0
|
39
|
-
def build
|
40
|
-
memoize ? build_memoized_dependency : build_original_dependency
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
23
|
|
45
|
-
|
46
|
-
#
|
47
|
-
# @api private
|
48
|
-
# @since 0.1.0
|
49
|
-
attr_reader :dependency_name
|
24
|
+
private
|
50
25
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
# @since 0.2.0
|
61
|
-
attr_reader :memoize
|
62
|
-
|
63
|
-
# @return [SmartCore::Container::Entities::Dependency]
|
64
|
-
#
|
65
|
-
# @api private
|
66
|
-
# @since 0.2.0
|
67
|
-
def build_memoized_dependency
|
68
|
-
SmartCore::Container::Entities::MemoizedDependency.new(dependency_name, dependency_definition)
|
69
|
-
end
|
26
|
+
# @param dependency_name [String]
|
27
|
+
# @param dependency_definition [Proc]
|
28
|
+
# @return [SmartCore::Container::Entities::Dependency]
|
29
|
+
#
|
30
|
+
# @api private
|
31
|
+
# @since 0.8.1
|
32
|
+
def build_memoized_dependency(dependency_name, dependency_definition)
|
33
|
+
SmartCore::Container::Entities::MemoizedDependency.new(dependency_name, dependency_definition)
|
34
|
+
end
|
70
35
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
36
|
+
# @param dependency_name [String]
|
37
|
+
# @param dependency_definition [Proc]
|
38
|
+
# @return [SmartCore::Container::Entities::Dependency]
|
39
|
+
#
|
40
|
+
# @api private
|
41
|
+
# @since 0.8.1
|
42
|
+
def build_original_dependency(dependency_name, dependency_definition)
|
43
|
+
SmartCore::Container::Entities::Dependency.new(dependency_name, dependency_definition)
|
44
|
+
end
|
77
45
|
end
|
78
46
|
end
|
@@ -15,11 +15,13 @@ module SmartCore::Container::Entities
|
|
15
15
|
@lock = SmartCore::Container::ArbitraryLock.new
|
16
16
|
end
|
17
17
|
|
18
|
+
# @param host_container [SmartCore::Container, NilClass]
|
18
19
|
# @return [Any]
|
19
20
|
#
|
20
21
|
# @api private
|
21
22
|
# @since 0.2.0
|
22
|
-
|
23
|
+
# @version 0.8.1
|
24
|
+
def reveal(host_container = SmartCore::Container::NO_HOST_CONTAINER)
|
23
25
|
@lock.thread_safe do
|
24
26
|
unless instance_variable_defined?(:@revealed_dependency)
|
25
27
|
@revealed_dependency = dependency_definition.call
|
@@ -9,24 +9,35 @@ class SmartCore::Container::Entities::Namespace < SmartCore::Container::Entities
|
|
9
9
|
# @since 0.1.0
|
10
10
|
alias_method :namespace_name, :external_name
|
11
11
|
|
12
|
+
# @return [NilClass, SmartCore::Container]
|
13
|
+
#
|
14
|
+
# @api private
|
15
|
+
# @since 0.8.01
|
16
|
+
attr_reader :host_container
|
17
|
+
|
12
18
|
# @param namespace_name [String]
|
19
|
+
# @param host_container [NilClass, SmartCore::Container]
|
13
20
|
# @return [void]
|
14
21
|
#
|
15
22
|
# @api private
|
16
23
|
# @since 0.1.0
|
17
|
-
|
24
|
+
# @version 0.8.1
|
25
|
+
def initialize(namespace_name, host_container = SmartCore::Container::NO_HOST_CONTAINER)
|
18
26
|
super(namespace_name)
|
19
27
|
@container_klass = Class.new(SmartCore::Container)
|
20
28
|
@container_instance = nil
|
29
|
+
@host_container = host_container
|
21
30
|
@lock = SmartCore::Container::ArbitraryLock.new
|
22
31
|
end
|
23
32
|
|
33
|
+
# @param runtime_host_container [SmartCore::Container, NilClass]
|
24
34
|
# @return [SmartCore::Container]
|
25
35
|
#
|
26
36
|
# @api private
|
27
37
|
# @since 0.1.0
|
28
|
-
|
29
|
-
|
38
|
+
# @version 0.8.1
|
39
|
+
def reveal(runtime_host_container = SmartCore::Container::NO_HOST_CONTAINER)
|
40
|
+
thread_safe { container_instance(runtime_host_container) }
|
30
41
|
end
|
31
42
|
|
32
43
|
# @param dependencies_definition [Proc]
|
@@ -54,12 +65,18 @@ class SmartCore::Container::Entities::Namespace < SmartCore::Container::Entities
|
|
54
65
|
# @since 0.1.0
|
55
66
|
attr_reader :container_klass
|
56
67
|
|
68
|
+
# @param runtime_host_container [SmartCore::Container, NilClass]
|
57
69
|
# @return [SmartCore::Container]
|
58
70
|
#
|
59
71
|
# @api private
|
60
72
|
# @since 0.1.0
|
61
|
-
|
62
|
-
|
73
|
+
# @version 0.8.1
|
74
|
+
def container_instance(runtime_host_container = SmartCore::Container::NO_HOST_CONTAINER)
|
75
|
+
@host_container ||= runtime_host_container
|
76
|
+
@container_instance ||= container_klass.new(
|
77
|
+
host_container: @host_container,
|
78
|
+
host_path: @host_container && namespace_name
|
79
|
+
)
|
63
80
|
end
|
64
81
|
|
65
82
|
# @param block [Block]
|
@@ -2,40 +2,20 @@
|
|
2
2
|
|
3
3
|
# @api private
|
4
4
|
# @since 0.1.0
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
5
|
+
# @version 0.8.1
|
6
|
+
module SmartCore::Container::Entities
|
7
|
+
module NamespaceBuilder
|
8
|
+
class << self
|
9
|
+
# @param namespace_name [String]
|
10
|
+
# @param host_container [SmartContainer, NilClass]
|
11
|
+
# @return [SmartCore::Container::Entities::Namespace]
|
12
|
+
#
|
13
|
+
# @api private
|
14
|
+
# @since 0.1.0
|
15
|
+
# @version 0.8.1
|
16
|
+
def build(namespace_name, host_container = SmartCore::Container::NO_HOST_CONTAINER)
|
17
|
+
SmartCore::Container::Entities::Namespace.new(namespace_name, host_container)
|
18
|
+
end
|
14
19
|
end
|
15
20
|
end
|
16
|
-
|
17
|
-
# @param namespace_name [String]
|
18
|
-
# @return [void]
|
19
|
-
#
|
20
|
-
# @api private
|
21
|
-
# @since 0.1.0
|
22
|
-
def initialize(namespace_name)
|
23
|
-
@namespace_name = namespace_name
|
24
|
-
end
|
25
|
-
|
26
|
-
# @return [SmartCore::Container::Entities::Namespace]
|
27
|
-
#
|
28
|
-
# @api private
|
29
|
-
# @since 0.1.0
|
30
|
-
def build
|
31
|
-
SmartCore::Container::Entities::Namespace.new(namespace_name)
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
# @return [String]
|
37
|
-
#
|
38
|
-
# @api private
|
39
|
-
# @since 0.1.0
|
40
|
-
attr_reader :namespace_name
|
41
21
|
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# @api private
|
4
|
+
# @since 0.8.1
|
5
|
+
class SmartCore::Container::Host
|
6
|
+
class << self
|
7
|
+
# @param container [SmartCore::Container]
|
8
|
+
# @param path [String]
|
9
|
+
# @return [SmartCore::Container::Host]
|
10
|
+
#
|
11
|
+
# @api private
|
12
|
+
# @since 0.8.1
|
13
|
+
def build(container, path) # rubocop:disable Metrics/AbcSize
|
14
|
+
if (container.nil? && !path.nil?) || (!container.nil? && path.nil?)
|
15
|
+
raise(SmartCore::Container::ArgumentError, <<~ERROR_MESSAGE)
|
16
|
+
Host container requires both host container instance and host container path
|
17
|
+
(container: #{container.inspect} / path: #{path.inspect})
|
18
|
+
ERROR_MESSAGE
|
19
|
+
end
|
20
|
+
|
21
|
+
if (!container.nil? && !path.nil?) &&
|
22
|
+
(!container.is_a?(SmartCore::Container) || !path.is_a?(String))
|
23
|
+
raise(SmartCore::Container::ArgumentError, <<~ERROR_MESSAGE)
|
24
|
+
Host container should be a type of SmartCore::Container
|
25
|
+
and host path should be a type of String.
|
26
|
+
ERROR_MESSAGE
|
27
|
+
end
|
28
|
+
|
29
|
+
new(container, path)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# @return [SmartCore::Container]
|
34
|
+
#
|
35
|
+
# @api private
|
36
|
+
# @since 0.8.1
|
37
|
+
attr_reader :container
|
38
|
+
|
39
|
+
# @return [String]
|
40
|
+
#
|
41
|
+
# @api private
|
42
|
+
# @since 0.8.1
|
43
|
+
attr_reader :path
|
44
|
+
|
45
|
+
# @return [Boolean]
|
46
|
+
#
|
47
|
+
# @api private
|
48
|
+
# @since 0.8.1
|
49
|
+
attr_reader :exists
|
50
|
+
alias_method :exists?, :exists
|
51
|
+
alias_method :present?, :exists
|
52
|
+
|
53
|
+
# @param container [SmartCore::Container]
|
54
|
+
# @param path [String]
|
55
|
+
# @return [void]
|
56
|
+
#
|
57
|
+
# @api private
|
58
|
+
# @since 0.8.1
|
59
|
+
def initialize(container, path)
|
60
|
+
@container = container
|
61
|
+
@path = path
|
62
|
+
@exists = !!container
|
63
|
+
end
|
64
|
+
|
65
|
+
# @param nested_entity_path [String]
|
66
|
+
# @return [void]
|
67
|
+
#
|
68
|
+
# @api private
|
69
|
+
# @since 0.8.1
|
70
|
+
def notify_about_nested_changement(nested_entity_path)
|
71
|
+
return unless exists?
|
72
|
+
host_path = "#{path}" \
|
73
|
+
"#{SmartCore::Container::DependencyResolver::PATH_PART_SEPARATOR}" \
|
74
|
+
"#{nested_entity_path}"
|
75
|
+
container.watcher.notify(host_path)
|
76
|
+
end
|
77
|
+
end
|
@@ -62,13 +62,19 @@ class SmartCore::Container::Registry
|
|
62
62
|
end
|
63
63
|
|
64
64
|
# @param name [String, Symbol]
|
65
|
+
# @param host_container [NilClasss, SmartCore::Container]
|
65
66
|
# @param dependencies_definition [Block]
|
66
67
|
# @return [void]
|
67
68
|
#
|
68
69
|
# @api private
|
69
70
|
# @since 0.1.0
|
70
|
-
|
71
|
-
|
71
|
+
# @version 0.8.1
|
72
|
+
def register_namespace(
|
73
|
+
name,
|
74
|
+
host_container = SmartCore::Container::NO_HOST_CONTAINER,
|
75
|
+
&dependencies_definition
|
76
|
+
)
|
77
|
+
thread_safe { add_namespace(name, host_container, dependencies_definition) }
|
72
78
|
end
|
73
79
|
|
74
80
|
# @return [void]
|
@@ -223,6 +229,7 @@ class SmartCore::Container::Registry
|
|
223
229
|
end
|
224
230
|
|
225
231
|
# @param namespace_name [String, Symbol]
|
232
|
+
# @param host_container [NilClass, SmartCore::Container]
|
226
233
|
# @param dependencies_definition [Proc]
|
227
234
|
# @return [SmartCore::Container::Entities::Namespace]
|
228
235
|
#
|
@@ -230,11 +237,13 @@ class SmartCore::Container::Registry
|
|
230
237
|
#
|
231
238
|
# @api private
|
232
239
|
# @since 0.1.0
|
233
|
-
|
240
|
+
# @version 0.8.1
|
241
|
+
def add_namespace(namespace_name, host_container, dependencies_definition)
|
234
242
|
if state_frozen?
|
235
243
|
raise(SmartCore::Container::FrozenRegistryError, 'Can not modify frozen registry!')
|
236
244
|
end
|
237
245
|
namespace_name = indifferently_accessable_name(namespace_name)
|
246
|
+
dependencies_definition ||= proc {}
|
238
247
|
prevent_dependency_overlap!(namespace_name)
|
239
248
|
|
240
249
|
# rubocop:disable Layout/RescueEnsureAlignment
|
@@ -242,7 +251,7 @@ class SmartCore::Container::Registry
|
|
242
251
|
fetch_entity(namespace_name)
|
243
252
|
rescue SmartCore::Container::FetchError
|
244
253
|
registry[namespace_name] = SmartCore::Container::Entities::NamespaceBuilder.build(
|
245
|
-
namespace_name
|
254
|
+
namespace_name, host_container
|
246
255
|
)
|
247
256
|
end
|
248
257
|
# rubocop:enable Layout/RescueEnsureAlignment
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_container
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rustam Ibragimov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: smart_engine
|
@@ -159,6 +159,7 @@ files:
|
|
159
159
|
- lib/smart_core/container/entities/namespace.rb
|
160
160
|
- lib/smart_core/container/entities/namespace_builder.rb
|
161
161
|
- lib/smart_core/container/errors.rb
|
162
|
+
- lib/smart_core/container/host.rb
|
162
163
|
- lib/smart_core/container/key_guard.rb
|
163
164
|
- lib/smart_core/container/mixin.rb
|
164
165
|
- lib/smart_core/container/registry.rb
|