smart_core 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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -1
  3. data/.rubocop.yml +1 -1
  4. data/.travis.yml +5 -8
  5. data/CHANGELOG.md +5 -0
  6. data/README.md +14 -4
  7. data/lib/smart_core.rb +2 -2
  8. data/lib/smart_core/container.rb +49 -56
  9. data/lib/smart_core/container/arbitary_lock.rb +22 -0
  10. data/lib/smart_core/container/definition_dsl.rb +105 -55
  11. data/lib/smart_core/container/{command_set.rb → definition_dsl/command_set.rb} +20 -26
  12. data/lib/smart_core/container/definition_dsl/commands.rb +12 -0
  13. data/lib/smart_core/container/{commands → definition_dsl/commands}/base.rb +3 -3
  14. data/lib/smart_core/container/definition_dsl/commands/definition/compose.rb +46 -0
  15. data/lib/smart_core/container/definition_dsl/commands/definition/namespace.rb +51 -0
  16. data/lib/smart_core/container/{commands → definition_dsl/commands/definition}/register.rb +13 -25
  17. data/lib/smart_core/container/definition_dsl/commands/instantiation/compose.rb +50 -0
  18. data/lib/smart_core/container/definition_dsl/commands/instantiation/freeze_state.rb +24 -0
  19. data/lib/smart_core/container/dependency_compatability.rb +3 -3
  20. data/lib/smart_core/container/dependency_compatability/definition.rb +42 -0
  21. data/lib/smart_core/container/dependency_compatability/general.rb +61 -0
  22. data/lib/smart_core/container/dependency_compatability/registry.rb +28 -29
  23. data/lib/smart_core/container/dependency_resolver.rb +9 -4
  24. data/lib/smart_core/container/entities.rb +11 -0
  25. data/lib/smart_core/container/{entity.rb → entities/base.rb} +7 -7
  26. data/lib/smart_core/container/entities/dependency.rb +38 -0
  27. data/lib/smart_core/container/entities/dependency_builder.rb +50 -0
  28. data/lib/smart_core/container/entities/namespace.rb +73 -0
  29. data/lib/smart_core/container/entities/namespace_builder.rb +41 -0
  30. data/lib/smart_core/container/errors.rb +43 -0
  31. data/lib/smart_core/container/key_guard.rb +5 -5
  32. data/lib/smart_core/container/mixin.rb +20 -16
  33. data/lib/smart_core/container/registry.rb +224 -201
  34. data/lib/smart_core/container/registry_builder.rb +38 -5
  35. data/lib/smart_core/{exceptions.rb → errors.rb} +0 -0
  36. data/lib/smart_core/operation.rb +3 -1
  37. data/lib/smart_core/operation/{custom.rb → callback.rb} +7 -7
  38. data/lib/smart_core/operation/result.rb +1 -1
  39. data/lib/smart_core/operation/result_interface.rb +3 -3
  40. data/lib/smart_core/version.rb +1 -1
  41. data/smart_core.gemspec +6 -5
  42. metadata +28 -38
  43. data/lib/smart_core/container/command_definer.rb +0 -117
  44. data/lib/smart_core/container/commands.rb +0 -9
  45. data/lib/smart_core/container/commands/namespace.rb +0 -53
  46. data/lib/smart_core/container/dependency.rb +0 -44
  47. data/lib/smart_core/container/dependency_builder.rb +0 -48
  48. data/lib/smart_core/container/dependency_compatability/abstract.rb +0 -59
  49. data/lib/smart_core/container/dependency_compatability/command_set.rb +0 -35
  50. data/lib/smart_core/container/exceptions.rb +0 -31
  51. data/lib/smart_core/container/memoized_dependency.rb +0 -28
  52. data/lib/smart_core/container/namespace.rb +0 -51
@@ -11,7 +11,7 @@ class SmartCore::Operation
11
11
  require_relative 'operation/success'
12
12
  require_relative 'operation/failure'
13
13
  require_relative 'operation/fatal'
14
- require_relative 'operation/custom'
14
+ require_relative 'operation/callback'
15
15
  require_relative 'operation/result_interface'
16
16
  require_relative 'operation/instance_builder'
17
17
 
@@ -30,6 +30,7 @@ class SmartCore::Operation
30
30
  # @param options [Hash<Symbol,Any>]
31
31
  # @param block [Proc]
32
32
  # @return [SmartCore::Operation::Success]
33
+ # @return [SmartCore::Operation::Callback]
33
34
  # @return [SmartCore::Operation::Failure]
34
35
  # @return [SmartCore::Operation::Fatal]
35
36
  #
@@ -41,6 +42,7 @@ class SmartCore::Operation
41
42
  end
42
43
 
43
44
  # @return [SmartCore::Operation::Success]
45
+ # @return [SmartCore::Operation::Callback]
44
46
  # @return [SmartCore::Operation::Failure]
45
47
  # @return [SmartCore::Operation::Fatal]
46
48
  # @return [Any]
@@ -2,27 +2,27 @@
2
2
 
3
3
  # @api public
4
4
  # @since 0.6.0
5
- class SmartCore::Operation::Custom < SmartCore::Operation::Result
5
+ class SmartCore::Operation::Callback < SmartCore::Operation::Result
6
6
  # @return [Block]
7
7
  #
8
8
  # @api public
9
9
  # @since 0.6.0
10
- attr_reader :custom_logic
10
+ attr_reader :callback
11
11
 
12
- # @param custom_logic [Block]
12
+ # @param callback [Block]
13
13
  # @return [void]
14
14
  #
15
15
  # @api public
16
16
  # @since 0.6.0
17
- def initialize(&custom_logic)
18
- @custom_logic = custom_logic
17
+ def initialize(&callback)
18
+ @callback = callback
19
19
  end
20
20
 
21
21
  # @return [Boolean]
22
22
  #
23
23
  # @api public
24
24
  # @since 0.6.0
25
- def custom?
25
+ def callback?
26
26
  true
27
27
  end
28
28
 
@@ -33,6 +33,6 @@ class SmartCore::Operation::Custom < SmartCore::Operation::Result
33
33
  # @api public
34
34
  # @since 0.6.0
35
35
  def call(*attributes, **options)
36
- custom_logic.call(*attributes, **options)
36
+ callback.call(*attributes, **options)
37
37
  end
38
38
  end
@@ -46,7 +46,7 @@ class SmartCore::Operation::Result
46
46
  #
47
47
  # @api public
48
48
  # @since 0.6.0
49
- def custom?
49
+ def callback?
50
50
  false
51
51
  end
52
52
  end
@@ -22,12 +22,12 @@ module SmartCore::Operation::ResultInterface
22
22
  end
23
23
 
24
24
  # @param custom_logic [Block]
25
- # @return [SmartCore::Operation::Custom]
25
+ # @return [SmartCore::Operation::Callback]
26
26
  #
27
27
  # @api public
28
28
  # @since 0.6.0
29
- def Custom(&custom_logic) # rubocop:disable Naming/MethodName
30
- SmartCore::Operation::Custom.new(&custom_logic)
29
+ def Callback(&custom_logic) # rubocop:disable Naming/MethodName
30
+ SmartCore::Operation::Callback.new(&custom_logic)
31
31
  end
32
32
 
33
33
  # @param errors [Array<Symbol|Any>]
@@ -5,5 +5,5 @@ module SmartCore
5
5
  #
6
6
  # @api public
7
7
  # @since 0.1.0
8
- VERSION = '0.6.0'
8
+ VERSION = '0.7.0'
9
9
  end
@@ -1,8 +1,9 @@
1
+ # coding: utf-8
1
2
  # frozen_string_literal: true
2
3
 
3
4
  lib = File.expand_path('lib', __dir__)
4
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'smart_core/version'
6
+ require_relative 'lib/smart_core/version'
6
7
 
7
8
  Gem::Specification.new do |spec|
8
9
  spec.required_ruby_version = '>= 2.3.8'
@@ -11,6 +12,7 @@ Gem::Specification.new do |spec|
11
12
  spec.version = SmartCore::VERSION
12
13
  spec.authors = ['Rustam Ibragimov']
13
14
  spec.email = ['iamdaiver@icloud.com']
15
+
14
16
  spec.summary = '(in active development) A set of common abstractions'
15
17
  spec.description = '(in active development) A set of common abstractions'
16
18
  spec.homepage = 'https://github.com/0exp/smart_core'
@@ -24,10 +26,9 @@ Gem::Specification.new do |spec|
24
26
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec|features)/}) }
25
27
  end
26
28
 
27
- spec.add_development_dependency 'coveralls', '~> 0.8'
28
- spec.add_development_dependency 'simplecov', '~> 0.16'
29
- spec.add_development_dependency 'armitage-rubocop', '~> 0.74'
30
- spec.add_development_dependency 'rspec', '~> 3.8'
29
+ spec.add_development_dependency 'simplecov', '~> 0.17'
30
+ spec.add_development_dependency 'armitage-rubocop', '~> 0.76'
31
+ spec.add_development_dependency 'rspec', '~> 3.9'
31
32
 
32
33
  spec.add_development_dependency 'bundler'
33
34
  spec.add_development_dependency 'rake'
metadata CHANGED
@@ -1,71 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rustam Ibragimov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-18 00:00:00.000000000 Z
11
+ date: 2019-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: coveralls
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '0.8'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '0.8'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: simplecov
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - "~>"
32
18
  - !ruby/object:Gem::Version
33
- version: '0.16'
19
+ version: '0.17'
34
20
  type: :development
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
24
  - - "~>"
39
25
  - !ruby/object:Gem::Version
40
- version: '0.16'
26
+ version: '0.17'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: armitage-rubocop
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - "~>"
46
32
  - !ruby/object:Gem::Version
47
- version: '0.74'
33
+ version: '0.76'
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - "~>"
53
39
  - !ruby/object:Gem::Version
54
- version: '0.74'
40
+ version: '0.76'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rspec
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: '3.8'
47
+ version: '3.9'
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
52
  - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: '3.8'
54
+ version: '3.9'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: bundler
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -130,29 +116,33 @@ files:
130
116
  - docs/SmartCore.pdf
131
117
  - lib/smart_core.rb
132
118
  - lib/smart_core/container.rb
133
- - lib/smart_core/container/command_definer.rb
134
- - lib/smart_core/container/command_set.rb
135
- - lib/smart_core/container/commands.rb
136
- - lib/smart_core/container/commands/base.rb
137
- - lib/smart_core/container/commands/namespace.rb
138
- - lib/smart_core/container/commands/register.rb
119
+ - lib/smart_core/container/arbitary_lock.rb
139
120
  - lib/smart_core/container/definition_dsl.rb
140
- - lib/smart_core/container/dependency.rb
141
- - lib/smart_core/container/dependency_builder.rb
121
+ - lib/smart_core/container/definition_dsl/command_set.rb
122
+ - lib/smart_core/container/definition_dsl/commands.rb
123
+ - lib/smart_core/container/definition_dsl/commands/base.rb
124
+ - lib/smart_core/container/definition_dsl/commands/definition/compose.rb
125
+ - lib/smart_core/container/definition_dsl/commands/definition/namespace.rb
126
+ - lib/smart_core/container/definition_dsl/commands/definition/register.rb
127
+ - lib/smart_core/container/definition_dsl/commands/instantiation/compose.rb
128
+ - lib/smart_core/container/definition_dsl/commands/instantiation/freeze_state.rb
142
129
  - lib/smart_core/container/dependency_compatability.rb
143
- - lib/smart_core/container/dependency_compatability/abstract.rb
144
- - lib/smart_core/container/dependency_compatability/command_set.rb
130
+ - lib/smart_core/container/dependency_compatability/definition.rb
131
+ - lib/smart_core/container/dependency_compatability/general.rb
145
132
  - lib/smart_core/container/dependency_compatability/registry.rb
146
133
  - lib/smart_core/container/dependency_resolver.rb
147
- - lib/smart_core/container/entity.rb
148
- - lib/smart_core/container/exceptions.rb
134
+ - lib/smart_core/container/entities.rb
135
+ - lib/smart_core/container/entities/base.rb
136
+ - lib/smart_core/container/entities/dependency.rb
137
+ - lib/smart_core/container/entities/dependency_builder.rb
138
+ - lib/smart_core/container/entities/namespace.rb
139
+ - lib/smart_core/container/entities/namespace_builder.rb
140
+ - lib/smart_core/container/errors.rb
149
141
  - lib/smart_core/container/key_guard.rb
150
- - lib/smart_core/container/memoized_dependency.rb
151
142
  - lib/smart_core/container/mixin.rb
152
- - lib/smart_core/container/namespace.rb
153
143
  - lib/smart_core/container/registry.rb
154
144
  - lib/smart_core/container/registry_builder.rb
155
- - lib/smart_core/exceptions.rb
145
+ - lib/smart_core/errors.rb
156
146
  - lib/smart_core/initializer.rb
157
147
  - lib/smart_core/initializer/attribute.rb
158
148
  - lib/smart_core/initializer/attribute/builder.rb
@@ -172,7 +162,7 @@ files:
172
162
  - lib/smart_core/initializer/type_set.rb
173
163
  - lib/smart_core/injector.rb
174
164
  - lib/smart_core/operation.rb
175
- - lib/smart_core/operation/custom.rb
165
+ - lib/smart_core/operation/callback.rb
176
166
  - lib/smart_core/operation/exceptions.rb
177
167
  - lib/smart_core/operation/failure.rb
178
168
  - lib/smart_core/operation/fatal.rb
@@ -1,117 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # @api private
4
- # @since 0.5.0
5
- class SmartCore::Container
6
- class CommandDefiner
7
- # @param container_klass [Class<SmartCore::Container>]
8
- # @return [void]
9
- #
10
- # @api private
11
- # @since 0.5.0
12
- def initialize(container_klass)
13
- @container_klass = container_klass
14
- @access_lock = Mutex.new
15
- end
16
-
17
- # @param namespace_name [String, Symbol]
18
- # @param dependency_definitions [Proc]
19
- # @return [void]
20
- #
21
- # @api private
22
- # @since 0.5.0
23
- def append_namespace(namespace_name, dependency_definitions)
24
- thread_safe do
25
- command = build_namespace_command(namespace_name, dependency_definitions)
26
- prevent_dependency_overlap!(command)
27
- append_command(command)
28
- end
29
- end
30
-
31
- # @param dependency_name [String, Symbol]
32
- # @param dependency_definition [Proc]
33
- # @param options [Hash<Symbol,Any>]
34
- # @return [void]
35
- #
36
- # @api private
37
- # @since 0.5.0
38
- def append_register(dependency_name, dependency_definition, options)
39
- thread_safe do
40
- command = build_register_command(dependency_name, dependency_definition, options)
41
- prevent_namespace_overlap!(command)
42
- append_command(command)
43
- end
44
- end
45
-
46
- private
47
-
48
- # @return [Class<SmartCore::Container>]
49
- #
50
- # @api private
51
- # @since 0.5.0
52
- attr_reader :container_klass
53
-
54
- # @param namespace_name [String]
55
- # @return [void]
56
- #
57
- # @api private
58
- # @since 0.5.0
59
- def prevent_dependency_overlap(namespace_name)
60
- DependencyCompatability::CommandSet.prevent_dependency_overlap!(
61
- container_klass, namespace_name
62
- )
63
- end
64
-
65
- # @param dependency_name [String]
66
- # @return [void]
67
- #
68
- # @api private
69
- # @since 0.5.0
70
- def prevent_namespace_overlap(dependency_name)
71
- DependencyCompatability::CommandSet.prevent_namespace_overlap!(
72
- container_klass, dependency_name
73
- )
74
- end
75
-
76
- # @param namespace_name [String]
77
- # @param dependency_definitions [Proc]
78
- # @return [SmartCore::Container::Commands::Namespace]
79
- #
80
- # @api private
81
- # @since 0.5.0
82
- def build_namespace_command(namespace_name, dependency_definitions)
83
- SmartCore::Container::Commands::Namespace.new(
84
- namespace_name, dependency_definitions
85
- )
86
- end
87
-
88
- # @param dependency_name [String]
89
- # @param dependency_definition [Proc]
90
- # @param option [Hash<Symbol,Any>]
91
- # @return [SmartCore::Container::Commands::Register]
92
- #
93
- def build_register_command(dependency_name, dependency_definition, options)
94
- SmartCore::Container::Commands::Register.new(
95
- dependency_name, dependency_definition, **options
96
- )
97
- end
98
-
99
- # @param command [SmartCore::Container::Commands::Base]
100
- # @return [void]
101
- #
102
- # @api private
103
- # @since 0.5.0
104
- def append_command(command)
105
- container_klass.__commands__.add_command(command)
106
- end
107
-
108
- # @param block [Block]
109
- # @return [Any]
110
- #
111
- # @api private
112
- # @since 0.5.0
113
- def thread_safe(&block)
114
- @access_lock.synchronize(&block)
115
- end
116
- end
117
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # @api private
4
- # @since 0.5.0
5
- module SmartCore::Container::Commands
6
- require_relative 'commands/base'
7
- require_relative 'commands/namespace'
8
- require_relative 'commands/register'
9
- end
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SmartCore::Container::Commands
4
- # @api private
5
- # @since 0.5.0
6
- class Namespace < Base
7
- # @return [String, Symbol]
8
- #
9
- # @api private
10
- # @since 0.5.0
11
- attr_reader :namespace_name
12
-
13
- # @param namespace_name [String, Symbol]
14
- # @param dependency_definitions [Proc]
15
- # @return [void]
16
- #
17
- # @see [SmartCore::Container::KeyGuard]
18
- #
19
- # @api private
20
- # @since 0.5.0
21
- def initialize(namespace_name, dependency_definitions)
22
- SmartCore::Container::KeyGuard.indifferently_accessable_key(namespace_name).tap do |name|
23
- @namespace_name = name
24
- @dependency_definitions = dependency_definitions
25
- end
26
- end
27
-
28
- # @param registry [SmartCore::Container::Registry]
29
- # @return [void]
30
- #
31
- # @api private
32
- # @since 0.5.0
33
- def call(registry)
34
- registry.namespace(namespace_name, &dependency_definitions)
35
- end
36
-
37
- # @return [SmartCore::Container::Commands::Namespace]
38
- #
39
- # @api private
40
- # @since 0.5.0
41
- def dup
42
- self.class.new(namespace_name, dependency_definitions)
43
- end
44
-
45
- private
46
-
47
- # @return [Proc]
48
- #
49
- # @api private
50
- # @since 0.5.0
51
- attr_reader :dependency_definitions
52
- end
53
- end