smart_injection 0.0.0.alpha → 0.0.0.alpha2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8648636507a04e403ca6e55d0371d3191d248e09e63f9c977128847fc382b00f
4
- data.tar.gz: 218f815047bf27cd213743ee0db5c82f7676beff59ccc95f0de5dad656a0e028
3
+ metadata.gz: 47305dc4c0d594df95939793e44ddecb0292fa3c81f8c6c8f7077a181b76a44f
4
+ data.tar.gz: '094e2d7c0b6030076856b3eb97c1b5a67bc01ab81ec61314d12ac44ed933ca1b'
5
5
  SHA512:
6
- metadata.gz: 8343d93be3d7fe20c1996255a8927d520e8a23a2f024d1af73b40346ddc59add22d4b09aa3b33a8afc744ce60638a68ea98c6beb249f5fdbec254243626b561e
7
- data.tar.gz: 256144d63e96bf91f2a2b60fd966935a4012c41cf509aa03159dac102c4eb9bc688fb207ec92f99928cb2e695ed5305a9e1601f7f3b0bfb1c386302baa319656
6
+ metadata.gz: 36467e0302f3404d16a21e11d949d30a8d1dfff2afc3e82f2f86364ee7ffa88f55cdc8d0acbedf6244df25da93211fecda6921d519e7d2a1121f2908aa36aa7b
7
+ data.tar.gz: 8774c415a69c2ce02c8675172aa914c97f21b31ef1a140dcd4435c4d6921a33a55265526b4a5c107f888d738934b608c46e04b5a35f684d9ea2c1e95b3e08498
@@ -25,6 +25,7 @@ module SmartCore
25
25
  # @since 0.1.0
26
26
  module Injection
27
27
  require_relative 'injection/version'
28
+ require_relative 'injection/errors'
28
29
  require_relative 'injection/injector'
29
30
  require_relative 'injection/locator'
30
31
  require_relative 'injection/dsl'
@@ -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
- attr_reader :__smart_injection_injector__
103
+ def __smart_injection_injector__
104
+ @__smart_injection_injector__
105
+ end
86
106
  end
87
107
  end
@@ -8,4 +8,8 @@ module SmartCore::Injection
8
8
  # @api public
9
9
  # @since 0.1.0
10
10
  ArgumentError = Class.new(SmartCore::ArgumentError)
11
+
12
+ # @api public
13
+ # @since 0.1.0
14
+ NoRegisteredContainersError = Class.new(Error)
11
15
  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
- raise(resolving_error)
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]
@@ -6,6 +6,6 @@ module SmartCore
6
6
  #
7
7
  # @api public
8
8
  # @since 0.1.0
9
- VERSION = '0.0.0.alpha'
9
+ VERSION = '0.0.0.alpha2'
10
10
  end
11
11
  end
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.alpha
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-05 00:00:00.000000000 Z
11
+ date: 2020-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: smart_engine