smart_container 0.6.0 → 0.7.0
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/.rubocop.yml +2 -2
- data/.travis.yml +6 -5
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +45 -30
- data/README.md +86 -2
- data/Rakefile +2 -1
- data/lib/smart_core/container.rb +18 -0
- data/lib/smart_core/container/version.rb +2 -2
- data/smart_container.gemspec +5 -5
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e536932a27a4bcf2ded83ea750978459e8dbf6a34ea35dfac8ef7008db3240d
|
4
|
+
data.tar.gz: 2566b21ef936d31bab5ff8eb6d6d51cd6510db97acf62d9dc55992915094a962
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1c443404d20ac8c6f61ea8bf6d37db0acd4e1131626ca00c75bf26f695262f275ee6814aab3ecd4b0a4c17b4d3f50ae449abb6932e658f0cc325e3e87cba8ea
|
7
|
+
data.tar.gz: 587dac41ae390e811802ca6c5a6a4610d81d4b7cecd1d5de224a409b1724edf180c98d78acc1a81cd9bc06010343d5a42f769acd219d12d395bef06c4f9420c6
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
@@ -2,18 +2,19 @@
|
|
2
2
|
language: ruby
|
3
3
|
cache: bundler
|
4
4
|
os: linux
|
5
|
+
dist: xenial
|
5
6
|
before_install:
|
6
|
-
- gem install bundler
|
7
|
+
- gem install bundler
|
7
8
|
script:
|
8
9
|
- bundle exec rake rubocop
|
9
10
|
- bundle exec rake rspec
|
10
11
|
jobs:
|
11
12
|
fast_finish: true
|
12
13
|
include:
|
13
|
-
- rvm: 2.4.
|
14
|
-
- rvm: 2.5.
|
15
|
-
- rvm: 2.6.
|
16
|
-
- rvm: 2.7.
|
14
|
+
- rvm: 2.4.10
|
15
|
+
- rvm: 2.5.8
|
16
|
+
- rvm: 2.6.6
|
17
|
+
- rvm: 2.7.1
|
17
18
|
- rvm: ruby-head
|
18
19
|
- rvm: jruby-head
|
19
20
|
allow_failures:
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [0.7.0] - 2020-06-20
|
5
|
+
### Added
|
6
|
+
- `SmartCore::Container.define {}` - an ability to avoid explicit class definition that allows
|
7
|
+
to create container instances from an anonymous container class imidietly
|
8
|
+
|
4
9
|
## [0.6.0] - 2020-01-12
|
5
10
|
### Added
|
6
11
|
- Missing memoization flag `:memoize` for runtime-based dependency registration:
|
data/Gemfile.lock
CHANGED
@@ -2,82 +2,97 @@ PATH
|
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
4
|
smart_container (0.6.0)
|
5
|
-
smart_engine (~> 0.
|
5
|
+
smart_engine (~> 0.5)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
|
11
|
-
|
10
|
+
activesupport (6.0.2.2)
|
11
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
|
+
i18n (>= 0.7, < 2)
|
13
|
+
minitest (~> 5.1)
|
14
|
+
tzinfo (~> 1.1)
|
15
|
+
zeitwerk (~> 2.2)
|
16
|
+
armitage-rubocop (0.81.0)
|
17
|
+
rubocop (= 0.81.0)
|
12
18
|
rubocop-performance (= 1.5.2)
|
13
|
-
rubocop-rails (= 2.
|
14
|
-
rubocop-rake (= 0.5.
|
15
|
-
rubocop-rspec (= 1.
|
19
|
+
rubocop-rails (= 2.5.2)
|
20
|
+
rubocop-rake (= 0.5.1)
|
21
|
+
rubocop-rspec (= 1.38.1)
|
16
22
|
ast (2.4.0)
|
17
23
|
coderay (1.1.2)
|
24
|
+
concurrent-ruby (1.1.6)
|
18
25
|
diff-lcs (1.3)
|
19
26
|
docile (1.3.2)
|
27
|
+
i18n (1.8.2)
|
28
|
+
concurrent-ruby (~> 1.0)
|
20
29
|
jaro_winkler (1.5.4)
|
21
|
-
|
22
|
-
|
30
|
+
method_source (1.0.0)
|
31
|
+
minitest (5.14.0)
|
23
32
|
parallel (1.19.1)
|
24
|
-
parser (2.7.0
|
33
|
+
parser (2.7.1.0)
|
25
34
|
ast (~> 2.4.0)
|
26
|
-
pry (0.
|
27
|
-
coderay (~> 1.1
|
28
|
-
method_source (~>
|
29
|
-
rack (2.
|
35
|
+
pry (0.13.1)
|
36
|
+
coderay (~> 1.1)
|
37
|
+
method_source (~> 1.0)
|
38
|
+
rack (2.2.2)
|
30
39
|
rainbow (3.0.0)
|
31
40
|
rake (13.0.1)
|
41
|
+
rexml (3.2.4)
|
32
42
|
rspec (3.9.0)
|
33
43
|
rspec-core (~> 3.9.0)
|
34
44
|
rspec-expectations (~> 3.9.0)
|
35
45
|
rspec-mocks (~> 3.9.0)
|
36
46
|
rspec-core (3.9.1)
|
37
47
|
rspec-support (~> 3.9.1)
|
38
|
-
rspec-expectations (3.9.
|
48
|
+
rspec-expectations (3.9.1)
|
39
49
|
diff-lcs (>= 1.2.0, < 2.0)
|
40
50
|
rspec-support (~> 3.9.0)
|
41
51
|
rspec-mocks (3.9.1)
|
42
52
|
diff-lcs (>= 1.2.0, < 2.0)
|
43
53
|
rspec-support (~> 3.9.0)
|
44
54
|
rspec-support (3.9.2)
|
45
|
-
rubocop (0.
|
55
|
+
rubocop (0.81.0)
|
46
56
|
jaro_winkler (~> 1.5.1)
|
47
57
|
parallel (~> 1.10)
|
48
|
-
parser (>= 2.
|
58
|
+
parser (>= 2.7.0.1)
|
49
59
|
rainbow (>= 2.2.2, < 4.0)
|
60
|
+
rexml
|
50
61
|
ruby-progressbar (~> 1.7)
|
51
|
-
unicode-display_width (>= 1.4.0, <
|
62
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
52
63
|
rubocop-performance (1.5.2)
|
53
64
|
rubocop (>= 0.71.0)
|
54
|
-
rubocop-rails (2.
|
65
|
+
rubocop-rails (2.5.2)
|
66
|
+
activesupport
|
55
67
|
rack (>= 1.1)
|
56
68
|
rubocop (>= 0.72.0)
|
57
|
-
rubocop-rake (0.5.
|
69
|
+
rubocop-rake (0.5.1)
|
58
70
|
rubocop
|
59
|
-
rubocop-rspec (1.
|
71
|
+
rubocop-rspec (1.38.1)
|
60
72
|
rubocop (>= 0.68.1)
|
61
73
|
ruby-progressbar (1.10.1)
|
62
|
-
simplecov (0.
|
74
|
+
simplecov (0.18.5)
|
63
75
|
docile (~> 1.1)
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
76
|
+
simplecov-html (~> 0.11)
|
77
|
+
simplecov-html (0.12.2)
|
78
|
+
smart_engine (0.5.0)
|
79
|
+
thread_safe (0.3.6)
|
80
|
+
tzinfo (1.2.7)
|
81
|
+
thread_safe (~> 0.1)
|
82
|
+
unicode-display_width (1.7.0)
|
83
|
+
zeitwerk (2.3.0)
|
69
84
|
|
70
85
|
PLATFORMS
|
71
86
|
ruby
|
72
87
|
|
73
88
|
DEPENDENCIES
|
74
|
-
armitage-rubocop (~> 0.
|
89
|
+
armitage-rubocop (~> 0.81)
|
75
90
|
bundler (~> 2.1)
|
76
|
-
pry (~> 0.
|
91
|
+
pry (~> 0.13)
|
77
92
|
rake (~> 13.0)
|
78
93
|
rspec (~> 3.9)
|
79
|
-
simplecov (~> 0.
|
94
|
+
simplecov (~> 0.18)
|
80
95
|
smart_container!
|
81
96
|
|
82
97
|
BUNDLED WITH
|
83
|
-
2.1.
|
98
|
+
2.1.4
|
data/README.md
CHANGED
@@ -45,6 +45,26 @@ class Container < SmartCore::Container
|
|
45
45
|
end
|
46
46
|
```
|
47
47
|
|
48
|
+
- mixin:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
# full documentaiton is coming;
|
52
|
+
|
53
|
+
class Application
|
54
|
+
include SmartCore::Container::Mixin
|
55
|
+
|
56
|
+
dependencies do
|
57
|
+
namespace(:database) do
|
58
|
+
register(:cache) { MemcachedClient.new }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# access:
|
64
|
+
Application.container
|
65
|
+
Application.new.container # NOTE: the same instance as Application.container
|
66
|
+
```
|
67
|
+
|
48
68
|
- container instantiation and dependency resolving:
|
49
69
|
|
50
70
|
```ruby
|
@@ -136,18 +156,82 @@ container.dependency?('random', memoized: true) # => false
|
|
136
156
|
container.dependency?('random', memoized: false) # => true
|
137
157
|
```
|
138
158
|
|
139
|
-
- state freeze:
|
159
|
+
- state freeze (`#freeze!`, `.#frozen?`):
|
140
160
|
|
141
161
|
```ruby
|
142
162
|
# documentation is coming;
|
143
163
|
```
|
144
164
|
|
145
|
-
- reloading:
|
165
|
+
- reloading (`#reload!):
|
146
166
|
|
147
167
|
```ruby
|
148
168
|
# documentation is coming;
|
149
169
|
```
|
150
170
|
|
171
|
+
- hash tree (`#hash_tree`, `#hash_tree(resolve_dependencies: true)`):
|
172
|
+
|
173
|
+
```ruby
|
174
|
+
# documentation is coming`;
|
175
|
+
```
|
176
|
+
|
177
|
+
- `SmartCore::Container.define` - avoid explicit class definition (allows to create container instance from an anonymous container class immidietly):
|
178
|
+
|
179
|
+
```ruby
|
180
|
+
# - create from empty container class -
|
181
|
+
|
182
|
+
AppContainer = SmartCore::Container.define do
|
183
|
+
namespace :database do
|
184
|
+
register(:logger) { Logger.new }
|
185
|
+
end
|
186
|
+
end # => an instance of Class<SmartCore::Container>
|
187
|
+
|
188
|
+
AppContainer.resolve('database.logger') # => #<Logger:0x00007f5f0f2f0158>
|
189
|
+
AppContainer['database.logger'] # => #<Logger:0x00007f5f0f2f0158>
|
190
|
+
```
|
191
|
+
|
192
|
+
```ruby
|
193
|
+
# - create from another container class with a custom sub-definitions -
|
194
|
+
|
195
|
+
class BasicContainer < SmartCore::Container
|
196
|
+
namespace(:api) do
|
197
|
+
register(:client) { Kickbox.new }
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
AppContainer = BasicContainer.define do
|
202
|
+
register(:db_driver) { Sequel }
|
203
|
+
end
|
204
|
+
# --- or ---
|
205
|
+
AppContainer = SmartCore::Container.define(BasicContainer) do
|
206
|
+
register(:db_driver) { Sequel }
|
207
|
+
end
|
208
|
+
|
209
|
+
AppContainer['api.client'] # => #<Kickbox:0x00007f5f0f2f0158> (BasicContainer dependency)
|
210
|
+
AppContainer['db_driver'] # => Sequel (AppContainer dependency)
|
211
|
+
```
|
212
|
+
|
213
|
+
---
|
214
|
+
|
215
|
+
## Roadmap
|
216
|
+
|
217
|
+
- support for instant dependency registration:
|
218
|
+
|
219
|
+
```ruby
|
220
|
+
# common (dynamic) way:
|
221
|
+
register('dependency_name') { dependency_value }
|
222
|
+
|
223
|
+
# instant way:
|
224
|
+
register('dependency_name', dependency_value)
|
225
|
+
```
|
226
|
+
|
227
|
+
- support for memoization ignorance during dependency resolving:
|
228
|
+
|
229
|
+
```ruby
|
230
|
+
resolve('logger', :allocate) # Draft
|
231
|
+
```
|
232
|
+
|
233
|
+
- container composition;
|
234
|
+
|
151
235
|
---
|
152
236
|
|
153
237
|
## Contributing
|
data/Rakefile
CHANGED
@@ -4,6 +4,7 @@ require 'bundler/gem_tasks'
|
|
4
4
|
require 'rspec/core/rake_task'
|
5
5
|
require 'rubocop'
|
6
6
|
require 'rubocop/rake_task'
|
7
|
+
require 'rubocop-rails'
|
7
8
|
require 'rubocop-performance'
|
8
9
|
require 'rubocop-rspec'
|
9
10
|
require 'rubocop-rake'
|
@@ -11,8 +12,8 @@ require 'rubocop-rake'
|
|
11
12
|
RuboCop::RakeTask.new(:rubocop) do |t|
|
12
13
|
config_path = File.expand_path(File.join('.rubocop.yml'), __dir__)
|
13
14
|
t.options = ['--config', config_path]
|
14
|
-
t.requires << 'rubocop-performance'
|
15
15
|
t.requires << 'rubocop-rspec'
|
16
|
+
t.requires << 'rubocop-performance'
|
16
17
|
t.requires << 'rubocop-rake'
|
17
18
|
end
|
18
19
|
|
data/lib/smart_core/container.rb
CHANGED
@@ -20,6 +20,24 @@ module SmartCore
|
|
20
20
|
require_relative 'container/dependency_resolver'
|
21
21
|
require_relative 'container/mixin'
|
22
22
|
|
23
|
+
class << self
|
24
|
+
# @param initial_container_klass [Class<SmartCore::Container>]
|
25
|
+
# @param container_definitions [Block]
|
26
|
+
# @return [SmartCore::Container]
|
27
|
+
#
|
28
|
+
# @api public
|
29
|
+
# @since 0.7.0
|
30
|
+
def define(initial_container_klass = self, &container_definitions)
|
31
|
+
unless initial_container_klass <= SmartCore::Container
|
32
|
+
raise(SmartCore::Container::ArgumentError, <<~ERROR_MESSAGE)
|
33
|
+
Base class should be a type of SmartCore::Container
|
34
|
+
ERROR_MESSAGE
|
35
|
+
end
|
36
|
+
|
37
|
+
Class.new(initial_container_klass, &container_definitions).new
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
23
41
|
# @since 0.4.0
|
24
42
|
include ::Enumerable
|
25
43
|
|
data/smart_container.gemspec
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require_relative 'lib/smart_core/container/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
|
-
spec.required_ruby_version = Gem::Requirement.new('>= 2.4.
|
6
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.4.10')
|
7
7
|
|
8
8
|
spec.name = 'smart_container'
|
9
9
|
spec.version = SmartCore::Container::VERSION
|
@@ -27,12 +27,12 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ['lib']
|
29
29
|
|
30
|
-
spec.add_dependency 'smart_engine', '~> 0.
|
30
|
+
spec.add_dependency 'smart_engine', '~> 0.5'
|
31
31
|
|
32
32
|
spec.add_development_dependency 'bundler', '~> 2.1'
|
33
33
|
spec.add_development_dependency 'rake', '~> 13.0'
|
34
34
|
spec.add_development_dependency 'rspec', '~> 3.9'
|
35
|
-
spec.add_development_dependency 'armitage-rubocop', '~> 0.
|
36
|
-
spec.add_development_dependency 'simplecov', '~> 0.
|
37
|
-
spec.add_development_dependency 'pry', '~> 0.
|
35
|
+
spec.add_development_dependency 'armitage-rubocop', '~> 0.81'
|
36
|
+
spec.add_development_dependency 'simplecov', '~> 0.18'
|
37
|
+
spec.add_development_dependency 'pry', '~> 0.13'
|
38
38
|
end
|
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.
|
4
|
+
version: 0.7.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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: smart_engine
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.5'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
26
|
+
version: '0.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,42 +72,42 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0.
|
75
|
+
version: '0.81'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0.
|
82
|
+
version: '0.81'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: simplecov
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0.
|
89
|
+
version: '0.18'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0.
|
96
|
+
version: '0.18'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: pry
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '0.
|
103
|
+
version: '0.13'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '0.
|
110
|
+
version: '0.13'
|
111
111
|
description: Thread-safe semanticaly-defined IoC/DI Container
|
112
112
|
email:
|
113
113
|
- iamdaiver@gmail.com
|
@@ -178,7 +178,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
178
178
|
requirements:
|
179
179
|
- - ">="
|
180
180
|
- !ruby/object:Gem::Version
|
181
|
-
version: 2.4.
|
181
|
+
version: 2.4.10
|
182
182
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
183
|
requirements:
|
184
184
|
- - ">="
|