smart_initializer 0.1.0.alpha4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/.travis.yml +36 -5
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +48 -31
- data/README.md +151 -22
- data/Rakefile +1 -1
- data/bin/rspec +54 -0
- data/gemfiles/with_external_deps.gemfile +7 -0
- data/gemfiles/with_external_deps.gemfile.lock +99 -0
- data/gemfiles/without_external_deps.gemfile +5 -0
- data/gemfiles/without_external_deps.gemfile.lock +97 -0
- data/lib/smart_core/initializer.rb +38 -35
- data/lib/smart_core/initializer/attribute.rb +12 -4
- data/lib/smart_core/initializer/attribute/factory.rb +47 -27
- data/lib/smart_core/initializer/attribute/parameters.rb +12 -4
- data/lib/smart_core/initializer/configurable_module.rb +27 -0
- data/lib/smart_core/initializer/configuration.rb +33 -0
- data/lib/smart_core/initializer/constructor.rb +9 -6
- data/lib/smart_core/initializer/constructor/definer.rb +34 -11
- data/lib/smart_core/initializer/dsl.rb +23 -6
- data/lib/smart_core/initializer/errors.rb +44 -0
- data/lib/smart_core/initializer/plugins.rb +17 -0
- data/lib/smart_core/initializer/plugins/abstract.rb +55 -0
- data/lib/smart_core/initializer/plugins/access_mixin.rb +47 -0
- data/lib/smart_core/initializer/plugins/registry.rb +166 -0
- data/lib/smart_core/initializer/plugins/registry_interface.rb +77 -0
- data/lib/smart_core/initializer/plugins/thy_types.rb +30 -0
- data/lib/smart_core/initializer/plugins/thy_types/errors.rb +11 -0
- data/lib/smart_core/initializer/plugins/thy_types/thy_types.rb +23 -0
- data/lib/smart_core/initializer/plugins/thy_types/thy_types/abstract_factory.rb +78 -0
- data/lib/smart_core/initializer/plugins/thy_types/thy_types/operation.rb +12 -0
- data/lib/smart_core/initializer/plugins/thy_types/thy_types/operation/base.rb +9 -0
- data/lib/smart_core/initializer/plugins/thy_types/thy_types/operation/cast.rb +21 -0
- data/lib/smart_core/initializer/plugins/thy_types/thy_types/operation/valid.rb +16 -0
- data/lib/smart_core/initializer/plugins/thy_types/thy_types/operation/validate.rb +19 -0
- data/lib/smart_core/initializer/settings.rb +49 -0
- data/lib/smart_core/initializer/settings/duplicator.rb +20 -0
- data/lib/smart_core/initializer/settings/type_system.rb +69 -0
- data/lib/smart_core/initializer/type_system.rb +16 -0
- data/lib/smart_core/initializer/type_system/interop.rb +103 -0
- data/lib/smart_core/initializer/type_system/interop/abstract_factory.rb +70 -0
- data/lib/smart_core/initializer/type_system/interop/aliasing.rb +72 -0
- data/lib/smart_core/initializer/type_system/interop/aliasing/alias_list.rb +141 -0
- data/lib/smart_core/initializer/type_system/interop/operation.rb +30 -0
- data/lib/smart_core/initializer/type_system/registry.rb +174 -0
- data/lib/smart_core/initializer/type_system/registry_interface.rb +102 -0
- data/lib/smart_core/initializer/type_system/smart_types.rb +48 -0
- data/lib/smart_core/initializer/type_system/smart_types/abstract_factory.rb +72 -0
- data/lib/smart_core/initializer/type_system/smart_types/operation.rb +13 -0
- data/lib/smart_core/initializer/type_system/smart_types/operation/base.rb +8 -0
- data/lib/smart_core/initializer/type_system/smart_types/operation/cast.rb +16 -0
- data/lib/smart_core/initializer/type_system/smart_types/operation/valid.rb +16 -0
- data/lib/smart_core/initializer/type_system/smart_types/operation/validate.rb +16 -0
- data/lib/smart_core/initializer/version.rb +1 -1
- data/smart_initializer.gemspec +13 -9
- metadata +67 -17
- data/lib/smart_core/initializer/attribute/init_extension.rb +0 -4
- data/lib/smart_core/initializer/type_aliasing.rb +0 -50
- data/lib/smart_core/initializer/type_aliasing/alias_list.rb +0 -101
@@ -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
|