smart_injection 0.0.0.alpha → 0.0.0.alpha2
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/lib/smart_core/injection.rb +1 -0
- data/lib/smart_core/injection/dsl.rb +24 -4
- data/lib/smart_core/injection/errors.rb +4 -0
- data/lib/smart_core/injection/injector.rb +23 -1
- data/lib/smart_core/injection/locator/container_proxy.rb +8 -1
- data/lib/smart_core/injection/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47305dc4c0d594df95939793e44ddecb0292fa3c81f8c6c8f7077a181b76a44f
|
4
|
+
data.tar.gz: '094e2d7c0b6030076856b3eb97c1b5a67bc01ab81ec61314d12ac44ed933ca1b'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36467e0302f3404d16a21e11d949d30a8d1dfff2afc3e82f2f86364ee7ffa88f55cdc8d0acbedf6244df25da93211fecda6921d519e7d2a1121f2908aa36aa7b
|
7
|
+
data.tar.gz: 8774c415a69c2ce02c8675172aa914c97f21b31ef1a140dcd4435c4d6921a33a55265526b4a5c107f888d738934b608c46e04b5a35f684d9ea2c1e95b3e08498
|
data/lib/smart_core/injection.rb
CHANGED
@@ -14,7 +14,27 @@ module SmartCore::Injection::DSL
|
|
14
14
|
:@__smart_injection_injector__,
|
15
15
|
SmartCore::Injection::Injector.new(base_klass)
|
16
16
|
)
|
17
|
+
|
17
18
|
base_klass.extend(ClassMethods)
|
19
|
+
base_klass.singleton_class.prepend(ClassInheritance)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# @api private
|
24
|
+
# @since 0.1.0
|
25
|
+
module ClassInheritance
|
26
|
+
# @param child_klass [Class]
|
27
|
+
# @return [void]
|
28
|
+
#
|
29
|
+
# @api private
|
30
|
+
# @since 0.1.0
|
31
|
+
def inherited(child_klass)
|
32
|
+
child_klass.instance_variable_set(
|
33
|
+
:@__smart_injection_injector__,
|
34
|
+
__smart_injection_injector__.duplicate_for(child_klass)
|
35
|
+
)
|
36
|
+
child_klass.singleton_class.prepend(ClassInheritance)
|
37
|
+
super
|
18
38
|
end
|
19
39
|
end
|
20
40
|
|
@@ -65,7 +85,7 @@ module SmartCore::Injection::DSL
|
|
65
85
|
# @api public
|
66
86
|
# @since 0.1.0
|
67
87
|
def register_container(*containers)
|
68
|
-
__smart_injection_injector__.register_container(containers)
|
88
|
+
__smart_injection_injector__.register_container(*containers)
|
69
89
|
end
|
70
90
|
|
71
91
|
# @return [Array<SmartCore::Container>]
|
@@ -76,12 +96,12 @@ module SmartCore::Injection::DSL
|
|
76
96
|
__smart_injection_injector__.associated_containers
|
77
97
|
end
|
78
98
|
|
79
|
-
private
|
80
|
-
|
81
99
|
# @return [SmartCore::Injection::Injector]
|
82
100
|
#
|
83
101
|
# @api private
|
84
102
|
# @since 0.1.0
|
85
|
-
|
103
|
+
def __smart_injection_injector__
|
104
|
+
@__smart_injection_injector__
|
105
|
+
end
|
86
106
|
end
|
87
107
|
end
|
@@ -50,7 +50,7 @@ class SmartCore::Injection::Injector
|
|
50
50
|
#
|
51
51
|
# @api private
|
52
52
|
# @since 0.1.0
|
53
|
-
def register_container(containers)
|
53
|
+
def register_container(*containers)
|
54
54
|
thread_safe { link_container(containers) }
|
55
55
|
end
|
56
56
|
|
@@ -62,6 +62,15 @@ class SmartCore::Injection::Injector
|
|
62
62
|
thread_safe { linked_containers.list }
|
63
63
|
end
|
64
64
|
|
65
|
+
# @param another_injectable [Class, Module]
|
66
|
+
# @return [SmartCore::Injection::Injector]
|
67
|
+
#
|
68
|
+
# @api private
|
69
|
+
# @since 0.1.0
|
70
|
+
def duplicate_for(another_injectable)
|
71
|
+
thread_safe { create_duplicate(another_injectable) }
|
72
|
+
end
|
73
|
+
|
65
74
|
private
|
66
75
|
|
67
76
|
# @return [Class, Module]
|
@@ -76,6 +85,19 @@ class SmartCore::Injection::Injector
|
|
76
85
|
# @since 0.1.0
|
77
86
|
attr_reader :linked_containers
|
78
87
|
|
88
|
+
# @param another_injectable [Class, Module]
|
89
|
+
# @return [SmartCore::Injection::Injector]
|
90
|
+
#
|
91
|
+
# @api private
|
92
|
+
# @since 0.1.0
|
93
|
+
def create_duplicate(another_injectable)
|
94
|
+
self.class.new(another_injectable).tap do |duplicate|
|
95
|
+
linked_containers.each do |container|
|
96
|
+
duplicate.register_container(container)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
79
101
|
# @param imports [Hash<String|Symbol,String>]
|
80
102
|
# @param memoize [Boolean]
|
81
103
|
# @param access [Symbol]
|
@@ -17,6 +17,7 @@ class SmartCore::Injection::Locator::ContainerProxy
|
|
17
17
|
# @param dependency_path [String]
|
18
18
|
# @return [Any]
|
19
19
|
#
|
20
|
+
# @raise [SmartCore::Injection::NoRegisteredContainersError]
|
20
21
|
# @raise [SmartCore::Container::ResolvingError]
|
21
22
|
#
|
22
23
|
# @api private
|
@@ -32,7 +33,13 @@ class SmartCore::Injection::Locator::ContainerProxy
|
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
35
|
-
|
36
|
+
unless resolving_error
|
37
|
+
raise(SmartCore::Injection::NoRegisteredContainersError, <<~ERROR_MESSAGE)
|
38
|
+
You haven't registered any containers for import.
|
39
|
+
ERROR_MESSAGE
|
40
|
+
else
|
41
|
+
raise(resolving_error)
|
42
|
+
end
|
36
43
|
end
|
37
44
|
|
38
45
|
# @param import_path [String]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_injection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.0.
|
4
|
+
version: 0.0.0.alpha2
|
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-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: smart_engine
|