smart_injection 0.0.0.alpha3 → 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +18 -29
- data/README.md +0 -85
- data/lib/smart_core/injection/version.rb +1 -1
- data/lib/smart_core/injection.rb +0 -33
- data/smart_injection.gemspec +3 -7
- metadata +4 -66
- data/lib/smart_core/injection/dsl.rb +0 -107
- data/lib/smart_core/injection/errors.rb +0 -15
- data/lib/smart_core/injection/injector/container_set/adding_listener.rb +0 -30
- data/lib/smart_core/injection/injector/container_set.rb +0 -113
- data/lib/smart_core/injection/injector/injection_settings/incompatability_control.rb +0 -113
- data/lib/smart_core/injection/injector/injection_settings.rb +0 -173
- data/lib/smart_core/injection/injector/modulizer.rb +0 -55
- data/lib/smart_core/injection/injector/strategies/method_injection.rb +0 -92
- data/lib/smart_core/injection/injector/strategies.rb +0 -7
- data/lib/smart_core/injection/injector.rb +0 -165
- data/lib/smart_core/injection/locator/container_proxy.rb +0 -142
- data/lib/smart_core/injection/locator/dependency.rb +0 -54
- data/lib/smart_core/injection/locator/factory.rb +0 -55
- data/lib/smart_core/injection/locator.rb +0 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f48169147897c8ce8f66b9f89612932e7f4928dfbd841a71333952e36fa2d8e
|
4
|
+
data.tar.gz: d8516b07187415d826c6370f3b03c7200c3c8df59cc04cba455aa815beda0f1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6258aebce545dafba8aaef29d7f137f322e097c60d7003d2dfd3bdc8d111845493f52909918c71bc233abc54c5c5c3b55dd7fd4b83d753f238bdf6a92c8c3704
|
7
|
+
data.tar.gz: 3f27d11d72af45e20fd2fbf393765be6414a2bb5e91b9dff4a797c13870fd36752702cc03cb9fd7e13acbea3632b2712e967ddf6e6bab6ef22c24e52bd70fad3
|
data/Gemfile.lock
CHANGED
@@ -1,41 +1,34 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
smart_injection (0.0.0
|
5
|
-
smart_container (~> 0.8, >= 0.8.1)
|
6
|
-
smart_engine (~> 0.7)
|
4
|
+
smart_injection (0.0.0)
|
7
5
|
|
8
6
|
GEM
|
9
7
|
remote: https://rubygems.org/
|
10
8
|
specs:
|
11
|
-
activesupport (6.0.3.
|
9
|
+
activesupport (6.0.3.1)
|
12
10
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
11
|
i18n (>= 0.7, < 2)
|
14
12
|
minitest (~> 5.1)
|
15
13
|
tzinfo (~> 1.1)
|
16
14
|
zeitwerk (~> 2.2, >= 2.2.2)
|
17
|
-
armitage-rubocop (0.85.
|
18
|
-
rubocop (= 0.85.
|
15
|
+
armitage-rubocop (0.85.0)
|
16
|
+
rubocop (= 0.85.0)
|
19
17
|
rubocop-performance (= 1.6.1)
|
20
|
-
rubocop-rails (= 2.
|
18
|
+
rubocop-rails (= 2.5.2)
|
21
19
|
rubocop-rake (= 0.5.1)
|
22
|
-
rubocop-rspec (= 1.
|
20
|
+
rubocop-rspec (= 1.39.0)
|
23
21
|
ast (2.4.1)
|
24
|
-
coderay (1.1.3)
|
25
22
|
concurrent-ruby (1.1.6)
|
26
|
-
diff-lcs (1.
|
23
|
+
diff-lcs (1.3)
|
27
24
|
docile (1.3.2)
|
28
25
|
i18n (1.8.3)
|
29
26
|
concurrent-ruby (~> 1.0)
|
30
|
-
method_source (1.0.0)
|
31
27
|
minitest (5.14.1)
|
32
|
-
parallel (1.19.
|
33
|
-
parser (2.7.1.
|
34
|
-
ast (~> 2.4.
|
35
|
-
|
36
|
-
coderay (~> 1.1)
|
37
|
-
method_source (~> 1.0)
|
38
|
-
rack (2.2.3)
|
28
|
+
parallel (1.19.1)
|
29
|
+
parser (2.7.1.3)
|
30
|
+
ast (~> 2.4.0)
|
31
|
+
rack (2.2.2)
|
39
32
|
rainbow (3.0.0)
|
40
33
|
rake (13.0.1)
|
41
34
|
regexp_parser (1.7.1)
|
@@ -53,7 +46,7 @@ GEM
|
|
53
46
|
diff-lcs (>= 1.2.0, < 2.0)
|
54
47
|
rspec-support (~> 3.9.0)
|
55
48
|
rspec-support (3.9.3)
|
56
|
-
rubocop (0.85.
|
49
|
+
rubocop (0.85.0)
|
57
50
|
parallel (~> 1.10)
|
58
51
|
parser (>= 2.7.0.1)
|
59
52
|
rainbow (>= 2.2.2, < 4.0)
|
@@ -62,31 +55,28 @@ GEM
|
|
62
55
|
rubocop-ast (>= 0.0.3)
|
63
56
|
ruby-progressbar (~> 1.7)
|
64
57
|
unicode-display_width (>= 1.4.0, < 2.0)
|
65
|
-
rubocop-ast (0.
|
58
|
+
rubocop-ast (0.0.3)
|
66
59
|
parser (>= 2.7.0.1)
|
67
60
|
rubocop-performance (1.6.1)
|
68
61
|
rubocop (>= 0.71.0)
|
69
|
-
rubocop-rails (2.
|
70
|
-
activesupport
|
62
|
+
rubocop-rails (2.5.2)
|
63
|
+
activesupport
|
71
64
|
rack (>= 1.1)
|
72
|
-
rubocop (>= 0.
|
65
|
+
rubocop (>= 0.72.0)
|
73
66
|
rubocop-rake (0.5.1)
|
74
67
|
rubocop
|
75
|
-
rubocop-rspec (1.
|
68
|
+
rubocop-rspec (1.39.0)
|
76
69
|
rubocop (>= 0.68.1)
|
77
70
|
ruby-progressbar (1.10.1)
|
78
71
|
simplecov (0.18.5)
|
79
72
|
docile (~> 1.1)
|
80
73
|
simplecov-html (~> 0.11)
|
81
74
|
simplecov-html (0.12.2)
|
82
|
-
smart_container (0.8.1)
|
83
|
-
smart_engine (~> 0.5)
|
84
|
-
smart_engine (0.7.0)
|
85
75
|
thread_safe (0.3.6)
|
86
76
|
tzinfo (1.2.7)
|
87
77
|
thread_safe (~> 0.1)
|
88
78
|
unicode-display_width (1.7.0)
|
89
|
-
zeitwerk (2.3.
|
79
|
+
zeitwerk (2.3.0)
|
90
80
|
|
91
81
|
PLATFORMS
|
92
82
|
ruby
|
@@ -94,7 +84,6 @@ PLATFORMS
|
|
94
84
|
DEPENDENCIES
|
95
85
|
armitage-rubocop (~> 0.85)
|
96
86
|
bundler (~> 2.1)
|
97
|
-
pry (~> 0.13)
|
98
87
|
rake (~> 13.0)
|
99
88
|
rspec (~> 3.9)
|
100
89
|
simplecov (~> 0.18)
|
data/README.md
CHANGED
@@ -2,26 +2,6 @@
|
|
2
2
|
|
3
3
|
Dependency injection principles and idioms realized in scope of Ruby.
|
4
4
|
|
5
|
-
---
|
6
|
-
|
7
|
-
## Major Features
|
8
|
-
|
9
|
-
- `method-injection` strategy
|
10
|
-
- `soon:` constructor injection strategy;
|
11
|
-
- `soon:` property injection strategy;
|
12
|
-
- realized as a mixin;
|
13
|
-
- instance-method dependency injection;
|
14
|
-
- class-method dependency injection;
|
15
|
-
- multiple IoC-container registration;
|
16
|
-
- static and dynamic bindings;
|
17
|
-
- support for memoization with run-time dependency-switchable re-memoization;
|
18
|
-
- an ability to import dependencies from the list of IoC-containers
|
19
|
-
- an ability to import from the pre-configured default IoC-container(s);
|
20
|
-
- an ability to import from any manually passed IoC-container;
|
21
|
-
- privacy control of injected dependency (public/private/protected);
|
22
|
-
|
23
|
-
---
|
24
|
-
|
25
5
|
## Installation
|
26
6
|
|
27
7
|
```ruby
|
@@ -40,71 +20,6 @@ require 'smart_core/injection'
|
|
40
20
|
|
41
21
|
---
|
42
22
|
|
43
|
-
## Synopsis
|
44
|
-
|
45
|
-
Create some containers:
|
46
|
-
|
47
|
-
```ruby
|
48
|
-
AppContainer = SmartCore::Container.define do
|
49
|
-
namespace(:data_storage) do
|
50
|
-
register(:main) { Sequel::Model.db }
|
51
|
-
register(:cache) { Redis.new }
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
ServiceContainer = SmartCore::Container.define do
|
56
|
-
namespace(:rands) do
|
57
|
-
register(:alphanum) { -> { SeureRandom.alphanumeric } }
|
58
|
-
register(:hex) { -> { SecureRandom.hex } }
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
GlobalContainer = SmartCore::Container.define do
|
63
|
-
namespace(:phone_clients) do
|
64
|
-
register(:nexmo) { Nexmo.new }
|
65
|
-
register(:twilio) { Twilio.new }
|
66
|
-
end
|
67
|
-
end
|
68
|
-
```
|
69
|
-
|
70
|
-
And work with dependency injection:
|
71
|
-
|
72
|
-
```ruby
|
73
|
-
class MiniService
|
74
|
-
include SmartCore::Injection
|
75
|
-
|
76
|
-
register_container(AppContainer)
|
77
|
-
register_container(ServiceContainer)
|
78
|
-
|
79
|
-
# --- or ---
|
80
|
-
include SmartCore::Injection(AppContainer, ServiceContainer)
|
81
|
-
|
82
|
-
# --- or ---
|
83
|
-
include SmartCore::Injection
|
84
|
-
register_container(AppContainer, ServiceContainer)
|
85
|
-
|
86
|
-
# import dependencies to an instance
|
87
|
-
import({ db: 'data_storage.main' }, bind: :dynamic, access: :private)
|
88
|
-
import({ rnd: 'rands.alphanum' }, bind: :static, memoize: true)
|
89
|
-
|
90
|
-
# import dependencies to a class
|
91
|
-
import_static({ cache: 'data_storage.cache', hexer: 'rands.hex' }, bind: :static)
|
92
|
-
|
93
|
-
# import from a non-registered container
|
94
|
-
import({ phone_client: 'phone_clients.nexmo' }, from: GlobalContainer)
|
95
|
-
|
96
|
-
def call
|
97
|
-
db # => returns data_storage.main
|
98
|
-
rnd # => returns rands.alphanum
|
99
|
-
self.class.cache # => returns data_storage.cache
|
100
|
-
self.class.hexer # => returns rands.hexer
|
101
|
-
phone_client # => returns phone_clients.nexmo
|
102
|
-
end
|
103
|
-
end
|
104
|
-
```
|
105
|
-
|
106
|
-
---
|
107
|
-
|
108
23
|
## Contributing
|
109
24
|
|
110
25
|
- Fork it ( https://github.com/smart-rb/smart_injection )
|
data/lib/smart_core/injection.rb
CHANGED
@@ -1,44 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'smart_core/container'
|
4
|
-
require 'set'
|
5
|
-
|
6
3
|
# @api public
|
7
4
|
# @since 0.1.0
|
8
5
|
module SmartCore
|
9
|
-
# TODO: обязательно учесть наследование
|
10
|
-
|
11
|
-
class << self
|
12
|
-
# @param containers [Array<SmartCore::Container>]
|
13
|
-
# @return [Module]
|
14
|
-
#
|
15
|
-
# @api public
|
16
|
-
# @since 0.1.0
|
17
|
-
# rubocop:disable Naming/MethodName
|
18
|
-
def Injection(*containers)
|
19
|
-
::SmartCore::Injection::Injector::Modulizer.with_containers(containers)
|
20
|
-
end
|
21
|
-
# rubocop:enable Naming/MethodName
|
22
|
-
end
|
23
|
-
|
24
6
|
# @api public
|
25
7
|
# @since 0.1.0
|
26
8
|
module Injection
|
27
9
|
require_relative 'injection/version'
|
28
|
-
require_relative 'injection/errors'
|
29
|
-
require_relative 'injection/injector'
|
30
|
-
require_relative 'injection/locator'
|
31
|
-
require_relative 'injection/dsl'
|
32
|
-
|
33
|
-
class << self
|
34
|
-
# @param base_klass [Class, Module]
|
35
|
-
# @return [void]
|
36
|
-
#
|
37
|
-
# @api private
|
38
|
-
# @since 0.1.0
|
39
|
-
def included(base_klass)
|
40
|
-
::SmartCore::Injection::Injector::Modulizer.inject_to(base_klass)
|
41
|
-
end
|
42
|
-
end
|
43
10
|
end
|
44
11
|
end
|
data/smart_injection.gemspec
CHANGED
@@ -5,10 +5,10 @@ require_relative 'lib/smart_core/injection/version'
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.required_ruby_version = Gem::Requirement.new('>= 2.4.10')
|
7
7
|
|
8
|
-
spec.name =
|
8
|
+
spec.name = "smart_injection"
|
9
9
|
spec.version = SmartCore::Injection::VERSION
|
10
|
-
spec.authors = [
|
11
|
-
spec.email = [
|
10
|
+
spec.authors = ["Rustam Ibragimov"]
|
11
|
+
spec.email = ["iamdaiver@gmail.com"]
|
12
12
|
|
13
13
|
spec.summary = 'DI principles and idioms realized in scope of Ruby'
|
14
14
|
spec.description = 'DI principles and idioms realized in scope of Ruby'
|
@@ -30,13 +30,9 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
31
|
spec.require_paths = ['lib']
|
32
32
|
|
33
|
-
spec.add_runtime_dependency 'smart_engine', '~> 0.7'
|
34
|
-
spec.add_runtime_dependency 'smart_container', '~> 0.8', '>= 0.8.1'
|
35
|
-
|
36
33
|
spec.add_development_dependency 'bundler', '~> 2.1'
|
37
34
|
spec.add_development_dependency 'rake', '~> 13.0'
|
38
35
|
spec.add_development_dependency 'rspec', '~> 3.9'
|
39
36
|
spec.add_development_dependency 'armitage-rubocop', '~> 0.85'
|
40
37
|
spec.add_development_dependency 'simplecov', '~> 0.18'
|
41
|
-
spec.add_development_dependency 'pry', '~> 0.13'
|
42
38
|
end
|
metadata
CHANGED
@@ -1,49 +1,15 @@
|
|
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
|
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-
|
11
|
+
date: 2020-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: smart_engine
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0.7'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0.7'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: smart_container
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0.8'
|
34
|
-
- - ">="
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: 0.8.1
|
37
|
-
type: :runtime
|
38
|
-
prerelease: false
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
40
|
-
requirements:
|
41
|
-
- - "~>"
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '0.8'
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 0.8.1
|
47
13
|
- !ruby/object:Gem::Dependency
|
48
14
|
name: bundler
|
49
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,20 +80,6 @@ dependencies:
|
|
114
80
|
- - "~>"
|
115
81
|
- !ruby/object:Gem::Version
|
116
82
|
version: '0.18'
|
117
|
-
- !ruby/object:Gem::Dependency
|
118
|
-
name: pry
|
119
|
-
requirement: !ruby/object:Gem::Requirement
|
120
|
-
requirements:
|
121
|
-
- - "~>"
|
122
|
-
- !ruby/object:Gem::Version
|
123
|
-
version: '0.13'
|
124
|
-
type: :development
|
125
|
-
prerelease: false
|
126
|
-
version_requirements: !ruby/object:Gem::Requirement
|
127
|
-
requirements:
|
128
|
-
- - "~>"
|
129
|
-
- !ruby/object:Gem::Version
|
130
|
-
version: '0.13'
|
131
83
|
description: DI principles and idioms realized in scope of Ruby
|
132
84
|
email:
|
133
85
|
- iamdaiver@gmail.com
|
@@ -149,20 +101,6 @@ files:
|
|
149
101
|
- bin/console
|
150
102
|
- bin/setup
|
151
103
|
- lib/smart_core/injection.rb
|
152
|
-
- lib/smart_core/injection/dsl.rb
|
153
|
-
- lib/smart_core/injection/errors.rb
|
154
|
-
- lib/smart_core/injection/injector.rb
|
155
|
-
- lib/smart_core/injection/injector/container_set.rb
|
156
|
-
- lib/smart_core/injection/injector/container_set/adding_listener.rb
|
157
|
-
- lib/smart_core/injection/injector/injection_settings.rb
|
158
|
-
- lib/smart_core/injection/injector/injection_settings/incompatability_control.rb
|
159
|
-
- lib/smart_core/injection/injector/modulizer.rb
|
160
|
-
- lib/smart_core/injection/injector/strategies.rb
|
161
|
-
- lib/smart_core/injection/injector/strategies/method_injection.rb
|
162
|
-
- lib/smart_core/injection/locator.rb
|
163
|
-
- lib/smart_core/injection/locator/container_proxy.rb
|
164
|
-
- lib/smart_core/injection/locator/dependency.rb
|
165
|
-
- lib/smart_core/injection/locator/factory.rb
|
166
104
|
- lib/smart_core/injection/version.rb
|
167
105
|
- smart_injection.gemspec
|
168
106
|
homepage: https://github.com/smart-rb/smart_injection
|
@@ -183,9 +121,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
183
121
|
version: 2.4.10
|
184
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
185
123
|
requirements:
|
186
|
-
- - "
|
124
|
+
- - ">="
|
187
125
|
- !ruby/object:Gem::Version
|
188
|
-
version:
|
126
|
+
version: '0'
|
189
127
|
requirements: []
|
190
128
|
rubygems_version: 3.1.2
|
191
129
|
signing_key:
|
@@ -1,107 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# @api public
|
4
|
-
# @since 0.1.0
|
5
|
-
module SmartCore::Injection::DSL
|
6
|
-
class << self
|
7
|
-
# @param base_klass [Class, Module]
|
8
|
-
# @return [void]
|
9
|
-
#
|
10
|
-
# @api private
|
11
|
-
# @since 0.1.0
|
12
|
-
def included(base_klass)
|
13
|
-
base_klass.instance_variable_set(
|
14
|
-
:@__smart_injection_injector__,
|
15
|
-
SmartCore::Injection::Injector.new(base_klass)
|
16
|
-
)
|
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
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# @api private
|
42
|
-
# @since 0.1.0
|
43
|
-
module ClassMethods
|
44
|
-
# @param imports [Hash<String|Symbol,String>]
|
45
|
-
# @option memoize [Boolean]
|
46
|
-
# @option access [Symbol]
|
47
|
-
# @option bind [Symbol]
|
48
|
-
# @option from [NilClass, SmartCore::Container]
|
49
|
-
# @return [void]
|
50
|
-
#
|
51
|
-
# @api public
|
52
|
-
# @sincd 0.1.0
|
53
|
-
def import(
|
54
|
-
imports,
|
55
|
-
memoize: SmartCore::Injection::Injector::InjectionSettings::DEFAULT_MEMOIZE,
|
56
|
-
access: SmartCore::Injection::Injector::InjectionSettings::DEFAULT_ACCESS,
|
57
|
-
bind: SmartCore::Injection::Injector::InjectionSettings::DEFAULT_BINDING_STRATEGY,
|
58
|
-
from: SmartCore::Injection::Injector::InjectionSettings::EMPTY_CONTAINER_DESTINATION
|
59
|
-
)
|
60
|
-
__smart_injection_injector__.inject(imports, memoize, access, bind, from)
|
61
|
-
end
|
62
|
-
|
63
|
-
# @param imports [Hash<String|Symbol,String>]
|
64
|
-
# @option memoize [Boolean]
|
65
|
-
# @option access [Symbol]
|
66
|
-
# @option bind [Symbol]
|
67
|
-
# @option from [NilClass, SmartCore::Container]
|
68
|
-
# @return [void]
|
69
|
-
#
|
70
|
-
# @api public
|
71
|
-
# @sincd 0.1.0
|
72
|
-
def import_static(
|
73
|
-
imports,
|
74
|
-
memoize: SmartCore::Injection::Injector::InjectionSettings::DEFAULT_MEMOIZE,
|
75
|
-
access: SmartCore::Injection::Injector::InjectionSettings::DEFAULT_ACCESS,
|
76
|
-
bind: SmartCore::Injection::Injector::InjectionSettings::DEFAULT_BINDING_STRATEGY,
|
77
|
-
from: SmartCore::Injection::Injector::InjectionSettings::EMPTY_CONTAINER_DESTINATION
|
78
|
-
)
|
79
|
-
__smart_injection_injector__.inject_static(imports, memoize, access, bind, from)
|
80
|
-
end
|
81
|
-
|
82
|
-
# @param containers [Array<SmartCore::Container>]
|
83
|
-
# @return [void]
|
84
|
-
#
|
85
|
-
# @api public
|
86
|
-
# @since 0.1.0
|
87
|
-
def register_container(*containers)
|
88
|
-
__smart_injection_injector__.register_container(*containers)
|
89
|
-
end
|
90
|
-
|
91
|
-
# @return [Array<SmartCore::Container>]
|
92
|
-
#
|
93
|
-
# @api public
|
94
|
-
# @since 0.1.0
|
95
|
-
def linked_containers
|
96
|
-
__smart_injection_injector__.associated_containers
|
97
|
-
end
|
98
|
-
|
99
|
-
# @return [SmartCore::Injection::Injector]
|
100
|
-
#
|
101
|
-
# @api private
|
102
|
-
# @since 0.1.0
|
103
|
-
def __smart_injection_injector__
|
104
|
-
@__smart_injection_injector__
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module SmartCore::Injection
|
4
|
-
# @api public
|
5
|
-
# @since 0.1.0
|
6
|
-
Error = Class.new(SmartCore::Error)
|
7
|
-
|
8
|
-
# @api public
|
9
|
-
# @since 0.1.0
|
10
|
-
ArgumentError = Class.new(SmartCore::ArgumentError)
|
11
|
-
|
12
|
-
# @api public
|
13
|
-
# @since 0.1.0
|
14
|
-
NoRegisteredContainersError = Class.new(Error)
|
15
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# @api private
|
4
|
-
# @since 0.1.0
|
5
|
-
class SmartCore::Injection::Injector::ContainerSet::AddingListener
|
6
|
-
# @param listener [Proc]
|
7
|
-
# @return [void]
|
8
|
-
#
|
9
|
-
# @api private
|
10
|
-
# @since 0.1.0
|
11
|
-
def initialize(listener)
|
12
|
-
@listener = listener
|
13
|
-
end
|
14
|
-
|
15
|
-
# @param cotnainer [SmartCore::Container]
|
16
|
-
#
|
17
|
-
# @api private
|
18
|
-
# @since 0.1.0
|
19
|
-
def notify(container)
|
20
|
-
listener.call(container)
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
# @return [Proc]
|
26
|
-
#
|
27
|
-
# @api private
|
28
|
-
# @since 0.1.0
|
29
|
-
attr_reader :listener
|
30
|
-
end
|
@@ -1,113 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# @api private
|
4
|
-
# @since 0.1.0
|
5
|
-
class SmartCore::Injection::Injector::ContainerSet
|
6
|
-
require_relative 'container_set/adding_listener'
|
7
|
-
|
8
|
-
# @since 0.1.0
|
9
|
-
include Enumerable
|
10
|
-
|
11
|
-
# @return [void]
|
12
|
-
#
|
13
|
-
# @api private
|
14
|
-
# @since 0.1.0
|
15
|
-
def initialize
|
16
|
-
@containers = [] # NOTE: we use Array cuz we need an ordered set
|
17
|
-
@adding_listeners = []
|
18
|
-
@access_lock = SmartCore::Engine::Lock.new
|
19
|
-
end
|
20
|
-
|
21
|
-
# @param container [SmartCore::Container]
|
22
|
-
# @return [void]
|
23
|
-
#
|
24
|
-
# @api private
|
25
|
-
# @since 0.1.0
|
26
|
-
def add(container)
|
27
|
-
thread_safe { append_container(container) }
|
28
|
-
end
|
29
|
-
alias_method :<<, :add
|
30
|
-
|
31
|
-
# @param listener [Block]
|
32
|
-
# @yield [container]
|
33
|
-
# @yieldparam container [SmartCore::Container]
|
34
|
-
# @return [void]
|
35
|
-
#
|
36
|
-
# @api private
|
37
|
-
# @since 0.1.0
|
38
|
-
def listen_addings(&listener)
|
39
|
-
thread_safe { add_adding_listener(listener) }
|
40
|
-
end
|
41
|
-
|
42
|
-
# @param block [Block]
|
43
|
-
# @yield [container]
|
44
|
-
# @yieldparam container [SmartCore::Container]
|
45
|
-
# @return [Enumerator]
|
46
|
-
#
|
47
|
-
# @api private
|
48
|
-
# @since 0.1.0
|
49
|
-
def each(&block)
|
50
|
-
thread_safe { block_given? ? containers.each(&block) : containers.each }
|
51
|
-
end
|
52
|
-
|
53
|
-
# @param block [Block]
|
54
|
-
# @yield [container]
|
55
|
-
# @yieldparam container [SmartCore::Container]
|
56
|
-
# @return [Enumerator]
|
57
|
-
#
|
58
|
-
# @api private
|
59
|
-
# @since 0.1.0
|
60
|
-
def reverse_each(&block)
|
61
|
-
thread_safe { block_given? ? containers.reverse_each(&block) : containers.reverse_each }
|
62
|
-
end
|
63
|
-
|
64
|
-
# @return [Array<SmartCore::Container>]
|
65
|
-
#
|
66
|
-
# @api private
|
67
|
-
# @since 0.1.0
|
68
|
-
def list
|
69
|
-
thread_safe { containers.dup }
|
70
|
-
end
|
71
|
-
|
72
|
-
private
|
73
|
-
|
74
|
-
# @return [Array<SmartCore::Container>]
|
75
|
-
#
|
76
|
-
# @api private
|
77
|
-
# @since 0.1.0
|
78
|
-
attr_reader :containers
|
79
|
-
|
80
|
-
# @return [Array<SmartCore::Injection::Injector::ContainerSet::AddingListener>]
|
81
|
-
attr_reader :adding_listeners
|
82
|
-
|
83
|
-
# @param listener [Proc]
|
84
|
-
# @return [void]
|
85
|
-
#
|
86
|
-
# @api private
|
87
|
-
# @since 0.1.0
|
88
|
-
def add_adding_listener(listener)
|
89
|
-
adding_listeners << SmartCore::Injection::Injector::ContainerSet::AddingListener.new(listener)
|
90
|
-
end
|
91
|
-
|
92
|
-
# @param container [SmartCore::Container]
|
93
|
-
# @return [void]
|
94
|
-
#
|
95
|
-
# @api private
|
96
|
-
# @since 0.1.0
|
97
|
-
def append_container(container)
|
98
|
-
# NOTE:
|
99
|
-
# - #concant is used to prevent container duplications in ordered set;
|
100
|
-
# - @containers should have an ordered unified container list;
|
101
|
-
containers.concat([container])
|
102
|
-
adding_listeners.each { |listener| listener.notify(container) }
|
103
|
-
end
|
104
|
-
|
105
|
-
# @param block [Block]
|
106
|
-
# @return [Any]
|
107
|
-
#
|
108
|
-
# @api private
|
109
|
-
# @since 0.1.0
|
110
|
-
def thread_safe(&block)
|
111
|
-
@access_lock.synchronize(&block)
|
112
|
-
end
|
113
|
-
end
|