smart_core 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -2
  3. data/.travis.yml +3 -3
  4. data/CHANGELOG.md +3 -0
  5. data/Gemfile +0 -3
  6. data/README.md +5 -33
  7. data/Rakefile +2 -0
  8. data/lib/smart_core/container/command_definer.rb +117 -0
  9. data/lib/smart_core/container/command_set.rb +82 -0
  10. data/lib/smart_core/container/commands/base.rb +12 -0
  11. data/lib/smart_core/container/commands/namespace.rb +53 -0
  12. data/lib/smart_core/container/commands/register.rb +63 -0
  13. data/lib/smart_core/container/commands.rb +9 -0
  14. data/lib/smart_core/container/definition_dsl.rb +66 -0
  15. data/lib/smart_core/container/dependency.rb +44 -0
  16. data/lib/smart_core/container/dependency_builder.rb +48 -0
  17. data/lib/smart_core/container/dependency_compatability/abstract.rb +59 -0
  18. data/lib/smart_core/container/dependency_compatability/command_set.rb +35 -0
  19. data/lib/smart_core/container/dependency_compatability/registry.rb +37 -0
  20. data/lib/smart_core/container/dependency_compatability.rb +9 -0
  21. data/lib/smart_core/container/dependency_resolver.rb +16 -0
  22. data/lib/smart_core/container/entity.rb +26 -0
  23. data/lib/smart_core/container/exceptions.rb +31 -0
  24. data/lib/smart_core/container/key_guard.rb +31 -0
  25. data/lib/smart_core/container/memoized_dependency.rb +28 -0
  26. data/lib/smart_core/container/mixin.rb +82 -0
  27. data/lib/smart_core/container/namespace.rb +51 -0
  28. data/lib/smart_core/container/registry.rb +227 -0
  29. data/lib/smart_core/container/registry_builder.rb +18 -0
  30. data/lib/smart_core/container.rb +123 -0
  31. data/lib/smart_core/exceptions.rb +23 -0
  32. data/lib/smart_core/initializer/attribute/builder.rb +99 -0
  33. data/lib/smart_core/initializer/attribute/value_finalizer/lambda.rb +32 -0
  34. data/lib/smart_core/initializer/attribute/value_finalizer/method.rb +32 -0
  35. data/lib/smart_core/initializer/attribute/value_finalizer.rb +24 -0
  36. data/lib/smart_core/initializer/attribute.rb +123 -0
  37. data/lib/smart_core/initializer/attribute_definer.rb +162 -0
  38. data/lib/smart_core/{operation → initializer}/attribute_set.rb +17 -17
  39. data/lib/smart_core/initializer/exceptions.rb +47 -0
  40. data/lib/smart_core/initializer/extension.rb +39 -0
  41. data/lib/smart_core/initializer/extension_definer.rb +62 -0
  42. data/lib/smart_core/initializer/extension_set.rb +75 -0
  43. data/lib/smart_core/{operation → initializer}/initialization_dsl.rb +82 -42
  44. data/lib/smart_core/initializer/instance_attribute_accessing.rb +49 -0
  45. data/lib/smart_core/initializer/instance_builder.rb +164 -0
  46. data/lib/smart_core/initializer/type.rb +49 -0
  47. data/lib/smart_core/initializer/type_set.rb +52 -0
  48. data/lib/smart_core/initializer.rb +89 -0
  49. data/lib/smart_core/injector.rb +6 -0
  50. data/lib/smart_core/operation/exceptions.rb +4 -20
  51. data/lib/smart_core/operation/instance_builder.rb +16 -124
  52. data/lib/smart_core/operation/state.rb +7 -0
  53. data/lib/smart_core/operation/step.rb +43 -0
  54. data/lib/smart_core/operation/step_set.rb +73 -0
  55. data/lib/smart_core/operation/success.rb +11 -0
  56. data/lib/smart_core/operation.rb +10 -12
  57. data/lib/smart_core/schema.rb +6 -0
  58. data/lib/smart_core/validator/commands.rb +2 -0
  59. data/lib/smart_core/validator/exceptions.rb +1 -1
  60. data/lib/smart_core/version.rb +1 -1
  61. data/lib/smart_core.rb +5 -0
  62. data/smart_core.gemspec +14 -14
  63. metadata +57 -15
  64. data/lib/smart_core/operation/attribute.rb +0 -66
  65. data/lib/smart_core/operation/attribute_definer.rb +0 -160
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 48849feae93285cc47dffdf7ded564e285a9294c85f33c12f46cca3f8ce2f0ac
4
- data.tar.gz: 8c4bb987bea2d13d68bef46d9c8e571e7ab05a4ec845e1066db83e5427dfb0b2
3
+ metadata.gz: da28c0f798db1236c70e630dc0f036260075038c6089d0640deec903ab72063b
4
+ data.tar.gz: b0bf5ff34eece47159f43acf3d7c870adcbcfc10c1f526a16a6c851587cbacb9
5
5
  SHA512:
6
- metadata.gz: 6bdc6cd853dbc1feef51a6f37609c529381aa2a8a9e36484f961648fe167459397a3068a33adafc7f7f80a6c291e9ea81e91dd3580a917b810d85d45115a0534
7
- data.tar.gz: d3938950ef78da94e8866870e7d1f08b6d122947507d7876d817a9e19788e89c98af040dfd05a3a917758e32142a3ac0af7ad902afa56fd1eb365d20bc2b4aa1
6
+ metadata.gz: 998f834b2631eb097b3824b00154cdea38103b488de00ae6022f29bddb2d012cfdd2b2039963d7663781e260a4bc841122ceaafaf26540b3dd18c77ac7d0a3fe
7
+ data.tar.gz: 838c859715897c223c11a6104efcb8110ff00a08f9897cc3e927ac8440a704528cc980262c0554628f967dd8980f6309648256f0b2199e20e7864315360b89db
data/.rubocop.yml CHANGED
@@ -5,7 +5,7 @@ inherit_gem:
5
5
 
6
6
  AllCops:
7
7
  UseCache: true
8
- TargetRubyVersion: 2.6.0
8
+ TargetRubyVersion: 2.6.3
9
9
  Include:
10
10
  - bin/console
11
11
  - lib/**/*.rb
@@ -14,6 +14,6 @@ AllCops:
14
14
  - Rakefile
15
15
  - smart_core.gemspec
16
16
 
17
- # NOTE: support for oldes ruby versions
17
+ # NOTE: support for old ruby versions
18
18
  Style/RedundantBegin:
19
19
  Enabled: false
data/.travis.yml CHANGED
@@ -6,9 +6,9 @@ matrix:
6
6
  fast_finish: true
7
7
  include:
8
8
  - rvm: 2.3.8
9
- - rvm: 2.4.5
10
- - rvm: 2.5.3
11
- - rvm: 2.6.0
9
+ - rvm: 2.4.6
10
+ - rvm: 2.5.5
11
+ - rvm: 2.6.3
12
12
  - rvm: ruby-head
13
13
  - rvm: jruby-head
14
14
  allow_failures:
data/CHANGELOG.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [0.5.0] - 2019-06-02
5
+ ### PRE-RELEASE
6
+
4
7
  ## [0.4.0] - 2019-01-27
5
8
  ### Added
6
9
  - **Valdiator**
data/Gemfile CHANGED
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  source 'https://rubygems.org'
4
-
5
4
  git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
-
7
- # Specify your gem's dependencies in smart_core.gemspec
8
5
  gemspec
data/README.md CHANGED
@@ -24,39 +24,11 @@ require 'smart_core'
24
24
 
25
25
  #### Completed abstractions:
26
26
 
27
- - [**Operation Object**](#operation-object) (aka `Service Object`) (`SmartCore::Operation`)
28
- - attribute definition DSL (`param`, `option`, `params`, `options`);
29
- - yieldable result object abstraction (`Success`, `Failure`, `Fatal`, `#success?`, `#failure?`, `#fatal?`);
30
- - yieldable `#call` (and `.call`);
31
- - inheritance works as expected `:)`;
32
- - no dependencies;
33
-
34
- - [**Validation Object**](#validation-object) (`SmartCore::Validator`)
35
- - support for nested validations;
36
- - inheritance works as expected `:)`;
37
- - `#error` - adds an error code;
38
- - `#fatal` - adds an error code and stops the current method execution flow;
39
- - command-style DSL;
40
- - thread-safe;
41
- - no dependencies;
42
-
43
- ---
44
-
45
- #### Operation Object
46
-
47
- ```ruby
48
- class Service < SmartCore::Operation
49
- # soon...
50
- end
51
- ```
52
-
53
- #### Validation Object
54
-
55
- ```ruby
56
- class Validator < SmartCore::Validator
57
- # soon...
58
- end
59
- ```
27
+ - Service Object (Operation, Functional Object);
28
+ - Initializer (DSL);
29
+ - Validator (Validation Layer);
30
+ - Dependency Container;
31
+ - (Soon) Schema;
60
32
 
61
33
  ---
62
34
 
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-rspec'
7
+ require 'rubocop-performance'
7
8
  require 'rubocop/rake_task'
8
9
 
9
10
  RuboCop::RakeTask.new(:rubocop) do |t|
@@ -11,6 +12,7 @@ RuboCop::RakeTask.new(:rubocop) do |t|
11
12
 
12
13
  t.options = ['--config', config_path]
13
14
  t.requires << 'rubocop-rspec'
15
+ t.requires << 'rubocop-performance'
14
16
  end
15
17
 
16
18
  RSpec::Core::RakeTask.new(:rspec)
@@ -0,0 +1,117 @@
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
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 0.5.0
5
+ class SmartCore::Container::CommandSet
6
+ # @since 0.5.0
7
+ include Enumerable
8
+
9
+ # @return [Array<SmartCore::Container::Commands::Base>]
10
+ #
11
+ # @api private
12
+ # @since 0.5.0
13
+ attr_reader :commands
14
+
15
+ # @api private
16
+ # @since 0.5.0
17
+ def initialize
18
+ @commands = []
19
+ @access_lock = Mutex.new
20
+ end
21
+
22
+ # @param command [SmartCore::Container::Commands::Base]
23
+ # @return [void]
24
+ #
25
+ # @api private
26
+ # @since 0.5.0
27
+ def add_command(command)
28
+ thread_safe { commands << command }
29
+ end
30
+ alias_method :<<, :add_command
31
+
32
+ # @yield [SmartCore::Container::Commands::Base]
33
+ # @return [Enumerable]
34
+ #
35
+ # @api private
36
+ # @since 0.5.0
37
+ def each(&block)
38
+ thread_safe { block_given? ? commands.each(&block) : commands.each }
39
+ end
40
+
41
+ # @param command_set [SmartCore::Container::CommandSet]
42
+ # @return [void]
43
+ #
44
+ # @api private
45
+ # @since 0.5.0
46
+ def concat(command_set)
47
+ thread_safe { commands.concat(command_set.dup.commands) }
48
+ end
49
+
50
+ # @return [SmartCore::Operation::AttributeSet]
51
+ #
52
+ # @api private
53
+ # @since 0.2.0
54
+ def dup
55
+ thread_safe do
56
+ self.class.new.tap do |duplicate|
57
+ commands.each do |command|
58
+ duplicate.add_command(command.dup)
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ # @return [void]
65
+ #
66
+ # @api private
67
+ # @since 0.5.0
68
+ def clear
69
+ thread_safe { commands.clear }
70
+ end
71
+
72
+ private
73
+
74
+ # @param block [Proc]
75
+ # @return [Any]
76
+ #
77
+ # @api private
78
+ # @since 0.5.0
79
+ def thread_safe(&block)
80
+ @access_lock.synchronize(&block)
81
+ end
82
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 0.5.0
5
+ class SmartCore::Container::Commands::Base
6
+ # @param regsitry [SmartCore::Container::Registry]
7
+ # @return [void]
8
+ #
9
+ # @api private
10
+ # @since 0.5.0
11
+ def call(registry); end
12
+ end
@@ -0,0 +1,53 @@
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
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SmartCore::Container::Commands
4
+ # @api private
5
+ # @since 0.5.0
6
+ class Register < Base
7
+ # @return [String, Symbol]
8
+ #
9
+ # @api private
10
+ # @since 0.5.0
11
+ attr_reader :dependency_name
12
+
13
+ # @param dependency_name [String, Symbol]
14
+ # @param options [Hash<Symbol,Any>]
15
+ # @param dependency_definition [Proc]
16
+ # @option memoize [Boolean]
17
+ # @return [void]
18
+ #
19
+ # @todo option list
20
+ # @see [SmartCore::Container::KeyGuard]
21
+ #
22
+ # @api private
23
+ # @since 0.5.0
24
+ def initialize(dependency_name, dependency_definition, **options)
25
+ SmartCore::Container::KeyGuard.indifferently_accessable_key(dependency_name).tap do |name|
26
+ @dependency_name = name
27
+ @options = options
28
+ @dependency_definition = dependency_definition
29
+ end
30
+ end
31
+
32
+ # @param registry [SmartCore::Container::Registry]
33
+ # @return [void]
34
+ #
35
+ # @api private
36
+ # @since 0.5.0
37
+ def call(registry)
38
+ registry.register(dependency_name, **options, &dependency_definition)
39
+ end
40
+
41
+ # @return [SmartCore::Container::Commands::Register]
42
+ #
43
+ # @api private
44
+ # @since 0.5.0
45
+ def dup
46
+ self.class.new(dependency_name, dependency_definition, **options)
47
+ end
48
+
49
+ private
50
+
51
+ # @return [Proc]
52
+ #
53
+ # @api private
54
+ # @since 0.5.0
55
+ attr_reader :dependency_definition
56
+
57
+ # @return [Hash<Symbol,Any>]
58
+ #
59
+ # @api private
60
+ # @since 0.5.0
61
+ attr_reader :options
62
+ end
63
+ end
@@ -0,0 +1,9 @@
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
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 0.5.0
5
+ module SmartCore::Container::DefinitionDSL
6
+ class << self
7
+ # @param base_klass [Class<SmartCore::Container>]
8
+ # @return [void]
9
+ #
10
+ # @api private
11
+ # @since 0.5.0
12
+ def included(base_klass)
13
+ base_klass.instance_variable_set(:@__commands__, SmartCore::Container::CommandSet.new)
14
+ base_klass.singleton_class.send(:attr_reader, :__commands__)
15
+ base_klass.extend(ClassMethods)
16
+ base_klass.singleton_class.prepend(ClassInheritance)
17
+ end
18
+ end
19
+
20
+ # @api private
21
+ # @since 0.5.0
22
+ module ClassInheritance
23
+ # @param child_klass [Class<SmartCore::Container>]
24
+ # @return [void]
25
+ #
26
+ # @api private
27
+ # @since 0.5.0
28
+ def inherited(child_klass)
29
+ child_klass.instance_variable_set(:@__commands__, SmartCore::Container::CommandSet.new)
30
+ child_klass.__commands__.concat(__commands__)
31
+ child_klass.singleton_class.prepend(ClassInheritance)
32
+ super
33
+ end
34
+ end
35
+
36
+ # @api private
37
+ # @since 0.5.0
38
+ module ClassMethods
39
+ # @param namespace_name [String, Symbol]
40
+ # @param dependency_definitions [Block]
41
+ # @return [void]
42
+ #
43
+ # @api public
44
+ # @since 0.5.0
45
+ def namespace(namespace_name, &dependency_definitions)
46
+ __commands__ << SmartCore::Container::Commands::Namespace.new(
47
+ namespace_name, dependency_definitions
48
+ )
49
+ end
50
+
51
+ # @param dependency_name [String, Symbol]
52
+ # @param options [Hash<Symbol,Any>]
53
+ # @param dependency_definition [Proc]
54
+ # @return [void]
55
+ #
56
+ # @todo option list
57
+ #
58
+ # @api public
59
+ # @since 0.5.0
60
+ def register(dependency_name, **options, &dependency_definition)
61
+ __commands__ << SmartCore::Container::Commands::Register.new(
62
+ dependency_name, dependency_definition, **options
63
+ )
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 0.5.0
5
+ class SmartCore::Container::Dependency < SmartCore::Container::Entity
6
+ # @param dependency_definition [Proc]
7
+ # @param options [Hash<Symbol,Any>]
8
+ # @return [void]
9
+ #
10
+ # @todo option list
11
+ #
12
+ # @api private
13
+ # @since 0.5.0
14
+ def initialize(external_name, dependency_definition, **options)
15
+ @dependency_definition = dependency_definition
16
+ @access_lock = Mutex.new
17
+ super(external_name)
18
+ end
19
+
20
+ # @return [Any]
21
+ #
22
+ # @api private
23
+ # @since 0.5.0
24
+ def call
25
+ thread_safe { dependency_definition.call }
26
+ end
27
+
28
+ private
29
+
30
+ # @return [Proc]
31
+ #
32
+ # @api private
33
+ # @since 0.5.0
34
+ attr_reader :dependency_definition
35
+
36
+ # @param block [Proc]
37
+ # @return [Any]
38
+ #
39
+ # @api private
40
+ # @since 0.5.0
41
+ def thread_safe(&block)
42
+ @access_lock.synchronize(&block)
43
+ end
44
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 0.5.0
5
+ module SmartCore::Container::DependencyBuilder
6
+ class << self
7
+ # @param external_name [String]
8
+ # @param dependency_definition [Proc]
9
+ # @option memoize [Boolean]
10
+ # @return [SmartCore::Container::Dependency, SmartCore::Container::MemoizedDependency]
11
+ #
12
+ # @api private
13
+ # @since 0.5.0
14
+ def build(external_name, dependency_definition, memoize: false, **options)
15
+ # @todo: raise an error if memoize is not a boolean
16
+
17
+ if memoize
18
+ build_memoized_dependency(external_name, dependency_definition, **options)
19
+ else
20
+ build_dependency(external_name, dependency_definition, **options)
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ # @param external_name [String]
27
+ # @param dependency_definition [Proc]
28
+ # @param options [Hash<Symbol,Any>]
29
+ # @return [SmartCore::Container::MemoizedDependency]
30
+ #
31
+ # @api private
32
+ # @since 0.5.0
33
+ def build_memoized_dependency(external_name, dependency_definition, **options)
34
+ SmartCore::Container::MemoizedDependency.new(external_name, dependency_definition, **options)
35
+ end
36
+
37
+ # @param external_name [String]
38
+ # @param dependency_definition [Proc]
39
+ # @param options [Hash<Symbol,Any>]
40
+ # @return [SmartCore::Container::Dependency]
41
+ #
42
+ # @api private
43
+ # @since 0.5.0
44
+ def build_dependency(external_name, dependency_definition, **options)
45
+ SmartCore::Container::Dependency.new(external_name, dependency_definition, **options)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 0.5.0
5
+ class SmartCore::Container::DependencyCompatability::Abstract
6
+ class << self
7
+ # @param dependency_root [Any]
8
+ # @param dependency_name [String]
9
+ # @return [void]
10
+ #
11
+ # @raise [SmartCore::Container::NamespaceOverlapError]
12
+ #
13
+ # @api private
14
+ # @since 0.5.0
15
+ def prevent_namespace_overlap!(dependency_root, dependency_name)
16
+ raise(
17
+ SmartCore::Container::NamespaceOverlapError,
18
+ "Trying to overlap already registered :#{dependency_name} " \
19
+ "namespace with :#{dependency_name} dependency!"
20
+ ) if potential_namespace_overlap?(dependency_root, dependency_name)
21
+ end
22
+
23
+ # @param dependency_root [Any]
24
+ # @param namespace_name [String]
25
+ # @return [void]
26
+ #
27
+ # @raise [SmartCore::Container::DependencyOverlapError]
28
+ #
29
+ # @api private
30
+ # @since 0.5.0
31
+ def prevent_dependency_overlap!(dependency_root, namespace_name)
32
+ raise(
33
+ SmartCore::Container::DependencyOverlapError,
34
+ "Trying to overlap already registered :#{namespace_name} " \
35
+ "dependency with :#{namespace_name} namespace!"
36
+ ) if potential_dependency_overlap?(dependency_root, namespace_name)
37
+ end
38
+
39
+ # @param dependency_root [Any]
40
+ # @param dependency [Any]
41
+ # @return [Boolean]
42
+ #
43
+ # @api private
44
+ # @since 0.5.0
45
+ def potential_namespace_overlap?(dependency_root, dependency)
46
+ raise NoMethodError
47
+ end
48
+
49
+ # @param dependency_root [Any]
50
+ # @param namespace [Any]
51
+ # @return [Boolean]
52
+ #
53
+ # @api private
54
+ # @since 0.5.0
55
+ def potential_dependency_overlap?(dependency_root, namespace)
56
+ raise NoMethodError
57
+ end
58
+ end
59
+ end