smart_core 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,44 +0,0 @@
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
@@ -1,48 +0,0 @@
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
@@ -1,59 +0,0 @@
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
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SmartCore::Container::DependencyCompatability
4
- # @api private
5
- # @since 0.5.0
6
- class CommandSet < Abstract
7
- class << self
8
- # @param command_set [SmartCore::Container::CommandSet]
9
- # @param dependency_name [String]
10
- # @return [Boolean]
11
- #
12
- # @api private
13
- # @since 0.5.0
14
- def potential_namespace_overlap?(command_set, dependency_name)
15
- command_set.any? do |command|
16
- next unless command.is_a?(SmartCore::Container::Commands::Namespace)
17
- command.namespace_name == dependency_name
18
- end
19
- end
20
-
21
- # @param command_set [SmartCore::Container::CommandSet]
22
- # @param namespace_name [String]
23
- # @return [Boolean]
24
- #
25
- # @api private
26
- # @since 0.5.0
27
- def potential_dependency_overlap?(command_set, namespace_name)
28
- command_set.any? do |command|
29
- next unless command.is_a?(SmartCore::Container::Commands::Register)
30
- command.dependency_name == namespace_name
31
- end
32
- end
33
- end
34
- end
35
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class SmartCore::Container
4
- # @api public
5
- # @since 0.5.0
6
- Error = Class.new(SmartCore::Error)
7
-
8
- # @api public
9
- # @since 0.5.0
10
- ArgumentError = Class.new(SmartCore::ArgumentError)
11
-
12
- # @api public
13
- # @since 0.5.0
14
- NamespaceOverlapError = Class.new(Error)
15
-
16
- # @api public
17
- # @since 0.5.0
18
- DependencyOverlapError = Class.new(Error)
19
-
20
- # @api public
21
- # @since 0.5.0
22
- UnexistentDependencyError = Class.new(Error)
23
-
24
- # @api public
25
- # @since 0.5.0
26
- FrozenRegistryError = Class.new(SmartCore::FrozenError)
27
-
28
- # @api private
29
- # @since 0.5.0
30
- IncompatibleDependencyTree = Class.new(Error)
31
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # @api private
4
- # @since 0.5.0
5
- class SmartCore::Container::MemoizedDependency < SmartCore::Container::Dependency
6
- # @param external_name [String]
7
- # @param dependency_definition [Proc]
8
- # @param options [Hash<Symbol,Any>]
9
- # @return [void]
10
- #
11
- # @todo option list
12
- # @see [SmartCore::Container::Dependency]
13
- #
14
- # @api private
15
- # @since 0.5.0
16
- def initialize(external_name, dependency_definition, **options)
17
- @memoized_call = nil
18
- super
19
- end
20
-
21
- # @return [Any]
22
- #
23
- # @api private
24
- # @since 0.5.0
25
- def call
26
- thread_safe { @memoized_call ||= dependency_definition.call }
27
- end
28
- end
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # @api private
4
- # @since 0.5.0
5
- class SmartCore::Container::Namespace < SmartCore::Container::Entity
6
- # @param external_name [String]
7
- # @return [void]
8
- #
9
- # @api private
10
- # @since 0.5.0
11
- def initialize(external_name)
12
- @container = Class.new(SmartCore::Container)
13
- @container_instance = nil
14
- @access_lock = Mutex.new
15
- super(external_name)
16
- end
17
-
18
- # @param dependency_definitions [Proc]
19
- # @return [void]
20
- #
21
- # @api private
22
- # @since 0.5.0
23
- def append_definitions(dependency_definitions)
24
- container.instance_eval(&dependency_definitions)
25
- end
26
-
27
- # @return [SmartCore::Container]
28
- #
29
- # @api private
30
- # @since 0.5.0
31
- def call
32
- thread_safe { @container_instance ||= container.new }
33
- end
34
-
35
- private
36
-
37
- # @return [Class<SmartCore::Container>]
38
- #
39
- # @api private
40
- # @since 0.5.0
41
- attr_reader :container
42
-
43
- # @param block [Proc]
44
- # @return [Any]
45
- #
46
- # @api private
47
- # @since 0.5.0
48
- def thread_safe(&block)
49
- @access_lock.synchronize(&block)
50
- end
51
- end