smart_initializer 0.1.0.alpha3 → 0.3.1

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 +1 -1
  3. data/.travis.yml +36 -5
  4. data/CHANGELOG.md +19 -0
  5. data/Gemfile.lock +63 -43
  6. data/README.md +227 -11
  7. data/Rakefile +1 -1
  8. data/bin/rspec +54 -0
  9. data/gemfiles/with_external_deps.gemfile +7 -0
  10. data/gemfiles/with_external_deps.gemfile.lock +102 -0
  11. data/gemfiles/without_external_deps.gemfile +5 -0
  12. data/gemfiles/without_external_deps.gemfile.lock +100 -0
  13. data/lib/smart_core/initializer.rb +44 -34
  14. data/lib/smart_core/initializer/attribute.rb +12 -5
  15. data/lib/smart_core/initializer/attribute/factory.rb +47 -27
  16. data/lib/smart_core/initializer/attribute/parameters.rb +12 -4
  17. data/lib/smart_core/initializer/configuration.rb +33 -0
  18. data/lib/smart_core/initializer/constructor.rb +35 -8
  19. data/lib/smart_core/initializer/{attribute → constructor}/definer.rb +64 -12
  20. data/lib/smart_core/initializer/dsl.rb +49 -10
  21. data/lib/smart_core/initializer/dsl/inheritance.rb +1 -0
  22. data/lib/smart_core/initializer/errors.rb +44 -0
  23. data/lib/smart_core/initializer/extensions.rb +9 -0
  24. data/lib/smart_core/initializer/extensions/abstract.rb +8 -0
  25. data/lib/smart_core/initializer/extensions/ext_init.rb +31 -0
  26. data/lib/smart_core/initializer/extensions/list.rb +74 -0
  27. data/lib/smart_core/initializer/functionality.rb +36 -0
  28. data/lib/smart_core/initializer/instance_attribute_accessing.rb +51 -0
  29. data/lib/smart_core/initializer/plugins.rb +17 -0
  30. data/lib/smart_core/initializer/plugins/abstract.rb +55 -0
  31. data/lib/smart_core/initializer/plugins/access_mixin.rb +47 -0
  32. data/lib/smart_core/initializer/plugins/registry.rb +166 -0
  33. data/lib/smart_core/initializer/plugins/registry_interface.rb +77 -0
  34. data/lib/smart_core/initializer/plugins/thy_types.rb +30 -0
  35. data/lib/smart_core/initializer/plugins/thy_types/errors.rb +11 -0
  36. data/lib/smart_core/initializer/plugins/thy_types/thy_types.rb +23 -0
  37. data/lib/smart_core/initializer/plugins/thy_types/thy_types/abstract_factory.rb +78 -0
  38. data/lib/smart_core/initializer/plugins/thy_types/thy_types/operation.rb +12 -0
  39. data/lib/smart_core/initializer/plugins/thy_types/thy_types/operation/base.rb +9 -0
  40. data/lib/smart_core/initializer/plugins/thy_types/thy_types/operation/cast.rb +21 -0
  41. data/lib/smart_core/initializer/plugins/thy_types/thy_types/operation/valid.rb +16 -0
  42. data/lib/smart_core/initializer/plugins/thy_types/thy_types/operation/validate.rb +19 -0
  43. data/lib/smart_core/initializer/settings.rb +49 -0
  44. data/lib/smart_core/initializer/settings/duplicator.rb +20 -0
  45. data/lib/smart_core/initializer/settings/type_system.rb +69 -0
  46. data/lib/smart_core/initializer/type_system.rb +16 -0
  47. data/lib/smart_core/initializer/type_system/interop.rb +103 -0
  48. data/lib/smart_core/initializer/type_system/interop/abstract_factory.rb +70 -0
  49. data/lib/smart_core/initializer/type_system/interop/aliasing.rb +72 -0
  50. data/lib/smart_core/initializer/type_system/interop/aliasing/alias_list.rb +141 -0
  51. data/lib/smart_core/initializer/type_system/interop/operation.rb +30 -0
  52. data/lib/smart_core/initializer/type_system/registry.rb +174 -0
  53. data/lib/smart_core/initializer/type_system/registry_interface.rb +102 -0
  54. data/lib/smart_core/initializer/type_system/smart_types.rb +48 -0
  55. data/lib/smart_core/initializer/type_system/smart_types/abstract_factory.rb +72 -0
  56. data/lib/smart_core/initializer/type_system/smart_types/operation.rb +13 -0
  57. data/lib/smart_core/initializer/type_system/smart_types/operation/base.rb +8 -0
  58. data/lib/smart_core/initializer/type_system/smart_types/operation/cast.rb +16 -0
  59. data/lib/smart_core/initializer/type_system/smart_types/operation/valid.rb +16 -0
  60. data/lib/smart_core/initializer/type_system/smart_types/operation/validate.rb +16 -0
  61. data/lib/smart_core/initializer/version.rb +2 -1
  62. data/smart_initializer.gemspec +13 -9
  63. metadata +73 -17
  64. data/lib/smart_core/initializer/type_aliasing.rb +0 -50
  65. data/lib/smart_core/initializer/type_aliasing/alias_list.rb +0 -101
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # @api private
4
- # @since 0.1.0
5
- module SmartCore::Initializer::TypeAliasing
6
- require_relative 'type_aliasing/alias_list'
7
-
8
- class << self
9
- # @param base_klass [Class]
10
- # @return [void]
11
- #
12
- # @api private
13
- # @since 0.1.0
14
- def extended(base_klass)
15
- base_klass.instance_variable_set(:@__type_aliases__, AliasList.new)
16
- base_klass.extend(ClassMethods)
17
- end
18
- end
19
-
20
- # @api private
21
- # @since 0.1.0
22
- module ClassMethods
23
- # @return [SmartCore::Initializer::TypeAliasing::AliasList]
24
- #
25
- # @api private
26
- # @since 0.1.0
27
- def __type_aliases__
28
- @__type_aliases__
29
- end
30
-
31
- # @param alias_name [String, Symbol]
32
- # @param type [SmartCore::Types::Primitive]
33
- # @return [void]
34
- #
35
- # @api public
36
- # @since 0.1.0
37
- def type_alias(alias_name, type)
38
- __type_aliases__.associate(alias_name, type)
39
- end
40
-
41
- # @param alias_name [String, Symbol]
42
- # @return [SmartCore::Types::Primitive]
43
- #
44
- # @api public
45
- # @since 0.1.0
46
- def type_from_alias(alias_name)
47
- __type_aliases__.resolve(alias_name)
48
- end
49
- end
50
- end
@@ -1,101 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # @api private
4
- # @since 0.1.0
5
- class SmartCore::Initializer::TypeAliasing::AliasList
6
- # @return [void]
7
- #
8
- # @api private
9
- # @since 0.1.0
10
- def initialize
11
- @list = {}
12
- @lock = SmartCore::Engine::Lock.new
13
- end
14
-
15
- # @param alias_name [String, Symbol]
16
- # @param type [SmartCore::Types::Primitive]
17
- # @return [void]
18
- #
19
- # @api private
20
- # @since 0.1.0
21
- def associate(alias_name, type)
22
- raise(
23
- SmartCore::Initializer::ArgumentError,
24
- 'Type alias should be a type of string or symbol'
25
- ) unless alias_name.is_a?(String) || alias_name.is_a?(Symbol)
26
-
27
- raise(
28
- SmartCore::Initializer::ArgumentError,
29
- 'Type object should be a type of SmartCore::Types::Primitive'
30
- ) unless type.is_a?(SmartCore::Types::Primitive)
31
-
32
- thread_safe { set_alias(alias_name, type) }
33
- end
34
-
35
- # @param alias_name [String, Symbol]
36
- # @return [SmartCore::Types::Primitive]
37
- #
38
- # @api private
39
- # @since 0.1.0
40
- def resolve(alias_name)
41
- raise(
42
- SmartCore::Initializer::ArgumentError,
43
- 'Type alias should be a type of string or symbol'
44
- ) unless alias_name.is_a?(String) || alias_name.is_a?(Symbol)
45
-
46
- thread_safe { get_alias(alias_name) }
47
- end
48
-
49
- private
50
-
51
- # @return [Hash<String,SmartCore::Types::Primitive>]
52
- #
53
- # @api private
54
- # @since 0.1.0
55
- attr_reader :list
56
-
57
- # @param block [Block]
58
- # @return [Any]
59
- #
60
- # @api private
61
- # @since 0.1.0
62
- def thread_safe(&block)
63
- @lock.synchronize(&block)
64
- end
65
-
66
- # @param alias_name [String, Symbol]
67
- # @param type [SmartCore::Types::Primitive]
68
- # @return [void]
69
- #
70
- # @api private
71
- # @since 0.1.0
72
- def set_alias(alias_name, type)
73
- alias_name = normalized_alias(alias_name)
74
- ::Warning.warn( # TODO: SmartCore::Engine::Instrumenting
75
- "[SmartCore::Initializer] Shadowing of already existing \"#{alias_name}\" type alias."
76
- ) if list.key?(alias_name)
77
- list[normalized_alias(alias_name)] = type
78
- end
79
-
80
- # @param alias_name [String, Symbol]
81
- # @return [SmartCore::Types::Primitive]
82
- #
83
- # @api private
84
- # @since 0.1.0
85
- def get_alias(alias_name)
86
- list.fetch(normalized_alias(alias_name)) do
87
- raise(SmartCore::Initializer::NoTypeAliasError, <<~ERROR_MESSAGE)
88
- Alias with name "#{alias_name}" does not exist
89
- ERROR_MESSAGE
90
- end
91
- end
92
-
93
- # @param alias_name [String, Symbol]
94
- # @return [String]
95
- #
96
- # @api private
97
- # @since 0.1.0
98
- def normalized_alias(alias_name)
99
- alias_name.to_s
100
- end
101
- end