smart_container 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +15 -0
  5. data/.travis.yml +28 -0
  6. data/CHANGELOG.md +6 -0
  7. data/CODE_OF_CONDUCT.md +74 -0
  8. data/Gemfile +4 -0
  9. data/Gemfile.lock +83 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +39 -0
  12. data/Rakefile +21 -0
  13. data/bin/console +8 -0
  14. data/bin/setup +8 -0
  15. data/lib/smart_core/container.rb +135 -0
  16. data/lib/smart_core/container/arbitary_lock.rb +22 -0
  17. data/lib/smart_core/container/definition_dsl.rb +109 -0
  18. data/lib/smart_core/container/definition_dsl/command_set.rb +87 -0
  19. data/lib/smart_core/container/definition_dsl/commands.rb +9 -0
  20. data/lib/smart_core/container/definition_dsl/commands/base.rb +48 -0
  21. data/lib/smart_core/container/definition_dsl/commands/definition.rb +9 -0
  22. data/lib/smart_core/container/definition_dsl/commands/definition/compose.rb +49 -0
  23. data/lib/smart_core/container/definition_dsl/commands/definition/namespace.rb +54 -0
  24. data/lib/smart_core/container/definition_dsl/commands/definition/register.rb +54 -0
  25. data/lib/smart_core/container/definition_dsl/commands/instantiation.rb +8 -0
  26. data/lib/smart_core/container/definition_dsl/commands/instantiation/compose.rb +53 -0
  27. data/lib/smart_core/container/definition_dsl/commands/instantiation/freeze_state.rb +27 -0
  28. data/lib/smart_core/container/definition_dsl/inheritance.rb +23 -0
  29. data/lib/smart_core/container/dependency_compatability.rb +9 -0
  30. data/lib/smart_core/container/dependency_compatability/definition.rb +38 -0
  31. data/lib/smart_core/container/dependency_compatability/general.rb +61 -0
  32. data/lib/smart_core/container/dependency_compatability/registry.rb +36 -0
  33. data/lib/smart_core/container/dependency_resolver.rb +93 -0
  34. data/lib/smart_core/container/dependency_resolver/route.rb +83 -0
  35. data/lib/smart_core/container/dependency_resolver/route/cursor.rb +47 -0
  36. data/lib/smart_core/container/entities.rb +11 -0
  37. data/lib/smart_core/container/entities/base.rb +26 -0
  38. data/lib/smart_core/container/entities/dependency.rb +38 -0
  39. data/lib/smart_core/container/entities/dependency_builder.rb +50 -0
  40. data/lib/smart_core/container/entities/namespace.rb +73 -0
  41. data/lib/smart_core/container/entities/namespace_builder.rb +41 -0
  42. data/lib/smart_core/container/errors.rb +65 -0
  43. data/lib/smart_core/container/key_guard.rb +31 -0
  44. data/lib/smart_core/container/mixin.rb +83 -0
  45. data/lib/smart_core/container/registry.rb +250 -0
  46. data/lib/smart_core/container/registry_builder.rb +51 -0
  47. data/lib/smart_core/container/version.rb +9 -0
  48. data/smart_container.gemspec +38 -0
  49. metadata +191 -0
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 0.1.0
5
+ module SmartCore::Container::RegistryBuilder
6
+ # rubocop:disable Layout/LineLength
7
+ class << self
8
+ # @parma container [SmartCore::Container]
9
+ # @option ignored_definition_commands [Array<Class::SmartCore::Container::DefinitionDSL::Commands::Base>>]
10
+ # @option ignored_instantiation_commands [Array<Class::SmartCore::Container::DefinitionDSL::Commands::Base>>]
11
+ # @return [SmartCore::Container::Registry]
12
+ #
13
+ # @api private
14
+ # @since 0.1.0
15
+ def build(container, ignored_definition_commands: [], ignored_instantiation_commands: [])
16
+ SmartCore::Container::Registry.new.tap do |registry|
17
+ build_definitions(container.class, registry, ignored_commands: ignored_definition_commands)
18
+ build_state(container.class, registry, ignored_commands: ignored_instantiation_commands)
19
+ end
20
+ end
21
+
22
+ # @param container_klass [Class<SmartCore::Container>]
23
+ # @param registry [SmartCore::Container::Registry]
24
+ # @option ignored_commands [Array<Class<SmartCore::Container::DefinitionDSL::Commands::Base>>]
25
+ # @return [void]
26
+ #
27
+ # @api private
28
+ # @since 0.1.0
29
+ def build_definitions(container_klass, registry, ignored_commands: [])
30
+ container_klass.__container_definition_commands__.each do |command|
31
+ next if ignored_commands.include?(command.class)
32
+ command.call(registry)
33
+ end
34
+ end
35
+
36
+ # @param container_klass [Class<SmartCore::Container>]
37
+ # @param registry [SmartCore::Container::Registry]
38
+ # @option ignored_commands [Array<Class<SmartCore::Container::DefinitionDSL::Commands::Base>>]
39
+ # @return [void]
40
+ #
41
+ # @api private
42
+ # @since 0.1.0
43
+ def build_state(container_klass, registry, ignored_commands: [])
44
+ container_klass.__container_instantiation_commands__.each do |command|
45
+ next if ignored_commands.include?(command.class)
46
+ command.call(registry)
47
+ end
48
+ end
49
+ end
50
+ # rubocop:enable Layout/LineLength
51
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SmartCore
4
+ class Container
5
+ # @api public
6
+ # @since 0.1.0
7
+ VERSION = '0.1.0'
8
+ end
9
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/smart_core/container/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.4.9')
7
+
8
+ spec.name = 'smart_container'
9
+ spec.version = SmartCore::Container::VERSION
10
+ spec.authors = ['Rustam Ibragimov']
11
+ spec.email = ['iamdaiver@gmail.com']
12
+
13
+ spec.summary = 'IoC/DI Container'
14
+ spec.description = 'Thread-safe semanticaly-defined IoC/DI Container'
15
+ spec.homepage = 'https://github.com/smart-rb/smart-container'
16
+ spec.license = 'MIT'
17
+
18
+ spec.metadata['homepage_uri'] = spec.homepage
19
+ spec.metadata['source_code_uri'] = 'https://github.com/smart-rb/smart-container'
20
+ spec.metadata['changelog_uri'] = 'https://github.com/smart-rb/smart-container/CHANGELOG.md'
21
+
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_dependency 'smart_engine', '~> 0.2'
31
+
32
+ spec.add_development_dependency 'bundler', '~> 2.1'
33
+ spec.add_development_dependency 'rake', '~> 13.0'
34
+ spec.add_development_dependency 'rspec', '~> 3.9'
35
+ spec.add_development_dependency 'armitage-rubocop', '~> 0.78'
36
+ spec.add_development_dependency 'simplecov', '~> 0.17'
37
+ spec.add_development_dependency 'pry', '~> 0.12'
38
+ end
metadata ADDED
@@ -0,0 +1,191 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smart_container
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rustam Ibragimov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-01-02 00:00:00.000000000 Z
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.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: armitage-rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.78'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.78'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.17'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.17'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.12'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.12'
111
+ description: Thread-safe semanticaly-defined IoC/DI Container
112
+ email:
113
+ - iamdaiver@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".rubocop.yml"
121
+ - ".travis.yml"
122
+ - CHANGELOG.md
123
+ - CODE_OF_CONDUCT.md
124
+ - Gemfile
125
+ - Gemfile.lock
126
+ - LICENSE.txt
127
+ - README.md
128
+ - Rakefile
129
+ - bin/console
130
+ - bin/setup
131
+ - lib/smart_core/container.rb
132
+ - lib/smart_core/container/arbitary_lock.rb
133
+ - lib/smart_core/container/definition_dsl.rb
134
+ - lib/smart_core/container/definition_dsl/command_set.rb
135
+ - lib/smart_core/container/definition_dsl/commands.rb
136
+ - lib/smart_core/container/definition_dsl/commands/base.rb
137
+ - lib/smart_core/container/definition_dsl/commands/definition.rb
138
+ - lib/smart_core/container/definition_dsl/commands/definition/compose.rb
139
+ - lib/smart_core/container/definition_dsl/commands/definition/namespace.rb
140
+ - lib/smart_core/container/definition_dsl/commands/definition/register.rb
141
+ - lib/smart_core/container/definition_dsl/commands/instantiation.rb
142
+ - lib/smart_core/container/definition_dsl/commands/instantiation/compose.rb
143
+ - lib/smart_core/container/definition_dsl/commands/instantiation/freeze_state.rb
144
+ - lib/smart_core/container/definition_dsl/inheritance.rb
145
+ - lib/smart_core/container/dependency_compatability.rb
146
+ - lib/smart_core/container/dependency_compatability/definition.rb
147
+ - lib/smart_core/container/dependency_compatability/general.rb
148
+ - lib/smart_core/container/dependency_compatability/registry.rb
149
+ - lib/smart_core/container/dependency_resolver.rb
150
+ - lib/smart_core/container/dependency_resolver/route.rb
151
+ - lib/smart_core/container/dependency_resolver/route/cursor.rb
152
+ - lib/smart_core/container/entities.rb
153
+ - lib/smart_core/container/entities/base.rb
154
+ - lib/smart_core/container/entities/dependency.rb
155
+ - lib/smart_core/container/entities/dependency_builder.rb
156
+ - lib/smart_core/container/entities/namespace.rb
157
+ - lib/smart_core/container/entities/namespace_builder.rb
158
+ - lib/smart_core/container/errors.rb
159
+ - lib/smart_core/container/key_guard.rb
160
+ - lib/smart_core/container/mixin.rb
161
+ - lib/smart_core/container/registry.rb
162
+ - lib/smart_core/container/registry_builder.rb
163
+ - lib/smart_core/container/version.rb
164
+ - smart_container.gemspec
165
+ homepage: https://github.com/smart-rb/smart-container
166
+ licenses:
167
+ - MIT
168
+ metadata:
169
+ homepage_uri: https://github.com/smart-rb/smart-container
170
+ source_code_uri: https://github.com/smart-rb/smart-container
171
+ changelog_uri: https://github.com/smart-rb/smart-container/CHANGELOG.md
172
+ post_install_message:
173
+ rdoc_options: []
174
+ require_paths:
175
+ - lib
176
+ required_ruby_version: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: 2.4.9
181
+ required_rubygems_version: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ version: '0'
186
+ requirements: []
187
+ rubygems_version: 3.1.2
188
+ signing_key:
189
+ specification_version: 4
190
+ summary: IoC/DI Container
191
+ test_files: []