smart_types 0.1.0 → 0.6.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 +6 -1
- data/CHANGELOG.md +57 -0
- data/Gemfile.lock +71 -58
- data/LICENSE.txt +1 -1
- data/README.md +363 -34
- data/Rakefile +0 -1
- data/bin/console +2 -2
- data/lib/smart_core/types/errors.rb +12 -0
- data/lib/smart_core/types/primitive/caster.rb +5 -2
- data/lib/smart_core/types/primitive/checker.rb +5 -2
- data/lib/smart_core/types/primitive/factory/definition_context.rb +140 -4
- data/lib/smart_core/types/primitive/factory/runtime_type_builder.rb +53 -0
- data/lib/smart_core/types/primitive/factory.rb +104 -7
- data/lib/smart_core/types/primitive/invariant_control/chain/result.rb +64 -0
- data/lib/smart_core/types/primitive/invariant_control/chain.rb +61 -0
- data/lib/smart_core/types/primitive/invariant_control/factory/chain_definition_context.rb +39 -0
- data/lib/smart_core/types/primitive/invariant_control/factory.rb +54 -0
- data/lib/smart_core/types/primitive/invariant_control/result.rb +104 -0
- data/lib/smart_core/types/primitive/invariant_control/single/result.rb +63 -0
- data/lib/smart_core/types/primitive/invariant_control/single.rb +57 -0
- data/lib/smart_core/types/primitive/invariant_control.rb +67 -0
- data/lib/smart_core/types/primitive/mult_factory/definition_context.rb +26 -2
- data/lib/smart_core/types/primitive/mult_factory.rb +59 -10
- data/lib/smart_core/types/primitive/mult_validator/result.rb +8 -0
- data/lib/smart_core/types/primitive/mult_validator.rb +42 -0
- data/lib/smart_core/types/primitive/nilable_factory.rb +31 -9
- data/lib/smart_core/types/primitive/nilable_validator/result.rb +78 -0
- data/lib/smart_core/types/primitive/nilable_validator.rb +83 -0
- data/lib/smart_core/types/primitive/runtime_attributes_checker.rb +77 -0
- data/lib/smart_core/types/primitive/sum_factory/definition_context.rb +25 -1
- data/lib/smart_core/types/primitive/sum_factory.rb +59 -10
- data/lib/smart_core/types/primitive/sum_validator/result.rb +100 -0
- data/lib/smart_core/types/primitive/sum_validator.rb +117 -0
- data/lib/smart_core/types/primitive/undefined_caster.rb +4 -1
- data/lib/smart_core/types/primitive/validator/result.rb +78 -0
- data/lib/smart_core/types/primitive/validator.rb +93 -0
- data/lib/smart_core/types/primitive.rb +99 -15
- data/lib/smart_core/types/protocol/instance_of.rb +19 -0
- data/lib/smart_core/types/protocol.rb +7 -0
- data/lib/smart_core/types/value/array.rb +3 -0
- data/lib/smart_core/types/value/big_decimal.rb +4 -1
- data/lib/smart_core/types/value/boolean.rb +3 -0
- data/lib/smart_core/types/value/class.rb +3 -0
- data/lib/smart_core/types/value/date.rb +3 -0
- data/lib/smart_core/types/value/date_time.rb +3 -0
- data/lib/smart_core/types/value/enumerable.rb +1 -1
- data/lib/smart_core/types/value/enumerator.rb +13 -0
- data/lib/smart_core/types/value/enumerator_chain.rb +13 -0
- data/lib/smart_core/types/value/float.rb +3 -0
- data/lib/smart_core/types/value/hash.rb +3 -0
- data/lib/smart_core/types/value/integer.rb +3 -0
- data/lib/smart_core/types/value/io.rb +13 -0
- data/lib/smart_core/types/value/method.rb +9 -0
- data/lib/smart_core/types/value/module.rb +3 -0
- data/lib/smart_core/types/value/nil.rb +0 -2
- data/lib/smart_core/types/value/numeric.rb +3 -0
- data/lib/smart_core/types/value/proc.rb +3 -0
- data/lib/smart_core/types/value/range.rb +9 -0
- data/lib/smart_core/types/value/rational.rb +13 -0
- data/lib/smart_core/types/value/set.rb +21 -0
- data/lib/smart_core/types/value/string.rb +3 -0
- data/lib/smart_core/types/value/string_io.rb +15 -0
- data/lib/smart_core/types/value/symbol.rb +3 -0
- data/lib/smart_core/types/value/text.rb +6 -4
- data/lib/smart_core/types/value/time.rb +3 -0
- data/lib/smart_core/types/value/time_based.rb +8 -5
- data/lib/smart_core/types/value/unbound_method.rb +9 -0
- data/lib/smart_core/types/value.rb +9 -0
- data/lib/smart_core/types/variadic/array_of.rb +23 -0
- data/lib/smart_core/types/variadic/enum.rb +11 -0
- data/lib/smart_core/types/variadic/tuple.rb +23 -0
- data/lib/smart_core/types/variadic.rb +10 -0
- data/lib/smart_core/types/version.rb +2 -1
- data/lib/smart_core/types.rb +2 -0
- data/smart_types.gemspec +5 -4
- metadata +61 -18
- data/.travis.yml +0 -21
- data/lib/smart_core/types/primitive/mult_checker.rb +0 -31
- data/lib/smart_core/types/primitive/nilable_checker.rb +0 -37
- data/lib/smart_core/types/primitive/sum_checker.rb +0 -31
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -13,6 +13,18 @@ module SmartCore::Types
|
|
13
13
|
# @since 0.1.0
|
14
14
|
NameError = Class.new(SmartCore::NameError)
|
15
15
|
|
16
|
+
# @api public
|
17
|
+
# @since 0.3.0
|
18
|
+
TypeDefinitionError = Class.new(ArgumentError)
|
19
|
+
|
20
|
+
# @api public
|
21
|
+
# @since 0.3.0
|
22
|
+
IncorrectRuntimeAttributesError = Class.new(TypeDefinitionError)
|
23
|
+
|
24
|
+
# @api public
|
25
|
+
# @since 0.3.0
|
26
|
+
RuntimeAttriburtesUnsupportedError = Class.new(TypeDefinitionError)
|
27
|
+
|
16
28
|
# @api public
|
17
29
|
# @since 0.1.0
|
18
30
|
TypeError = Class.new(SmartCore::TypeError)
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
# @api private
|
4
4
|
# @since 0.1.0
|
5
|
+
# @version 0.3.0
|
5
6
|
class SmartCore::Types::Primitive::Caster
|
6
7
|
# @param expression [Proc]
|
7
8
|
# @return [void]
|
@@ -13,12 +14,14 @@ class SmartCore::Types::Primitive::Caster
|
|
13
14
|
end
|
14
15
|
|
15
16
|
# @param value [Any]
|
17
|
+
# @param runtime_attributes [Array<Any>]
|
16
18
|
# @return [Any]
|
17
19
|
#
|
18
20
|
# @api private
|
19
21
|
# @since 0.1.0
|
20
|
-
|
21
|
-
|
22
|
+
# @version 0.3.0
|
23
|
+
def call(value, runtime_attributes)
|
24
|
+
expression.call(value, runtime_attributes)
|
22
25
|
end
|
23
26
|
|
24
27
|
private
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
# @api private
|
4
4
|
# @since 0.1.0
|
5
|
+
# @version 0.3.0
|
5
6
|
class SmartCore::Types::Primitive::Checker
|
6
7
|
# @param expression [Proc]
|
7
8
|
# @return [void]
|
@@ -13,12 +14,14 @@ class SmartCore::Types::Primitive::Checker
|
|
13
14
|
end
|
14
15
|
|
15
16
|
# @param value [Any]
|
17
|
+
# @param runtime_attributes [Array<Any>]
|
16
18
|
# @return [Boolean]
|
17
19
|
#
|
18
20
|
# @api private
|
19
21
|
# @since 0.1.0
|
20
|
-
|
21
|
-
|
22
|
+
# @version 0.3.0
|
23
|
+
def call(value, runtime_attributes)
|
24
|
+
!!expression.call(value, runtime_attributes)
|
22
25
|
end
|
23
26
|
|
24
27
|
private
|
@@ -2,7 +2,59 @@
|
|
2
2
|
|
3
3
|
# @api private
|
4
4
|
# @since 0.1.0
|
5
|
+
# @version 0.3.0
|
5
6
|
class SmartCore::Types::Primitive::Factory::DefinitionContext
|
7
|
+
class << self
|
8
|
+
# @param name [String, Symbol]
|
9
|
+
# @param definition [Block]
|
10
|
+
# @return [void]
|
11
|
+
#
|
12
|
+
# @api private
|
13
|
+
# @since 0.2.0
|
14
|
+
# @version 0.3.0
|
15
|
+
def vaildate_invariant_attributes!(name, &definition)
|
16
|
+
unless block_given?
|
17
|
+
raise(SmartCore::Types::TypeDefinitionError, 'No invariant block')
|
18
|
+
end
|
19
|
+
|
20
|
+
unless name.is_a?(::String) || name.is_a?(::Symbol)
|
21
|
+
raise(SmartCore::Types::TypeDefinitionError, <<~ERROR_MESSAGE)
|
22
|
+
Invariant name should be a type of string or symbol.
|
23
|
+
ERROR_MESSAGE
|
24
|
+
end
|
25
|
+
|
26
|
+
if name == '' || name == :""
|
27
|
+
raise(SmartCore::Types::TypeDefinitionError, <<~ERROR_MESSAGE)
|
28
|
+
Invariant name can not be empty.
|
29
|
+
ERROR_MESSAGE
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param chain_name [String, Symbol]
|
34
|
+
# @param definition [Block]
|
35
|
+
# @return [void]
|
36
|
+
#
|
37
|
+
# @api private
|
38
|
+
# @since 0.3.0
|
39
|
+
def vaildate_invariant_chain_attributes!(chain_name, &definition)
|
40
|
+
unless block_given?
|
41
|
+
raise(SmartCore::Types::TypeDefinitionError, 'No invariant chain block')
|
42
|
+
end
|
43
|
+
|
44
|
+
unless chain_name.is_a?(::String) || chain_name.is_a?(::Symbol)
|
45
|
+
raise(SmartCore::Types::TypeDefinitionError, <<~ERROR_MESSAGE)
|
46
|
+
Invariant chain name should be a type of string or symbol.
|
47
|
+
ERROR_MESSAGE
|
48
|
+
end
|
49
|
+
|
50
|
+
if chain_name == '' || chain_name == :""
|
51
|
+
raise(SmartCore::Types::TypeDefinitionError, <<~ERROR_MESSAGE)
|
52
|
+
Invariant chain name can not be empty.
|
53
|
+
ERROR_MESSAGE
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
6
58
|
# @return [Proc, NilClass]
|
7
59
|
#
|
8
60
|
# @api private
|
@@ -15,13 +67,36 @@ class SmartCore::Types::Primitive::Factory::DefinitionContext
|
|
15
67
|
# @since 0.1.0
|
16
68
|
attr_reader :type_caster
|
17
69
|
|
70
|
+
# @return [Hash<String,Array<Proc>>]
|
71
|
+
#
|
72
|
+
# @api private
|
73
|
+
# @since 0.2.0
|
74
|
+
attr_reader :type_invariant_chains
|
75
|
+
|
76
|
+
# @return [Hash<String,Proc>]
|
77
|
+
#
|
78
|
+
# @api private
|
79
|
+
# @since 0.2.0
|
80
|
+
attr_reader :type_invariants
|
81
|
+
|
82
|
+
# @return [Proc, NilClass]
|
83
|
+
#
|
84
|
+
# @api private
|
85
|
+
# @since 0.3.0
|
86
|
+
attr_reader :type_runtime_attributes_checker
|
87
|
+
|
18
88
|
# @return [void]
|
19
89
|
#
|
20
90
|
# @api private
|
21
91
|
# @since 0.1.0
|
92
|
+
# @version 0.2.0
|
22
93
|
def initialize
|
94
|
+
@type_invariant_chains = Hash.new { |h, k| h[k] = [] }
|
95
|
+
@type_invariants = {}
|
23
96
|
@type_checker = nil
|
24
97
|
@type_caster = nil
|
98
|
+
@type_runtime_attributes_checker = nil
|
99
|
+
@definition_lock = SmartCore::Engine::Lock.new
|
25
100
|
end
|
26
101
|
|
27
102
|
# @param checker [Block]
|
@@ -29,9 +104,14 @@ class SmartCore::Types::Primitive::Factory::DefinitionContext
|
|
29
104
|
#
|
30
105
|
# @api public
|
31
106
|
# @since 0.1.0
|
107
|
+
# @version 0.3.0
|
32
108
|
def define_checker(&checker)
|
33
|
-
|
34
|
-
|
109
|
+
thread_safe do
|
110
|
+
unless block_given?
|
111
|
+
raise(SmartCore::Types::TypeDefinitionError, 'No checker definition block')
|
112
|
+
end
|
113
|
+
@type_checker = checker
|
114
|
+
end
|
35
115
|
end
|
36
116
|
|
37
117
|
# @param caster [Block]
|
@@ -39,8 +119,64 @@ class SmartCore::Types::Primitive::Factory::DefinitionContext
|
|
39
119
|
#
|
40
120
|
# @api public
|
41
121
|
# @since 0.1.0
|
122
|
+
# @version 0.3.0
|
42
123
|
def define_caster(&caster)
|
43
|
-
|
44
|
-
|
124
|
+
thread_safe do
|
125
|
+
unless block_given?
|
126
|
+
raise(SmartCore::Types::TypeDefinitionError, 'No caster definition block')
|
127
|
+
end
|
128
|
+
@type_caster = caster
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# @param chain_name [String, Symbol]
|
133
|
+
# @param definitions [Block]
|
134
|
+
# @return [void]
|
135
|
+
#
|
136
|
+
# @api public
|
137
|
+
# @since 0.2.0
|
138
|
+
def invariant_chain(chain_name, &definitions)
|
139
|
+
thread_safe do
|
140
|
+
self.class.vaildate_invariant_chain_attributes!(chain_name, &definitions)
|
141
|
+
@type_invariant_chains[chain_name.to_s] << definitions
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
# @param name [String, Symbol]
|
146
|
+
# @param definition [Block]
|
147
|
+
# @return [void]
|
148
|
+
#
|
149
|
+
# @api public
|
150
|
+
# @since 0.2.0
|
151
|
+
def invariant(name, &definition)
|
152
|
+
thread_safe do
|
153
|
+
self.class.vaildate_invariant_attributes!(name, &definition)
|
154
|
+
@type_invariants[name.to_s] = definition
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
# @param definition [Block]
|
159
|
+
# @return [void]
|
160
|
+
#
|
161
|
+
# @api public
|
162
|
+
# @since 0.3.0
|
163
|
+
def runtime_attributes_checker(&definition)
|
164
|
+
thread_safe do
|
165
|
+
unless block_given?
|
166
|
+
raise(SmartCore::Types::TypeDefinitionError, 'No runtime checker definition block')
|
167
|
+
end
|
168
|
+
@type_runtime_attributes_checker = definition
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
private
|
173
|
+
|
174
|
+
# @param block [Block]
|
175
|
+
# @return [Any]
|
176
|
+
#
|
177
|
+
# @api private
|
178
|
+
# @since 0.2.0
|
179
|
+
def thread_safe(&block)
|
180
|
+
@definition_lock.synchronize(&block)
|
45
181
|
end
|
46
182
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# @api private
|
4
|
+
# @since 0.3.0
|
5
|
+
module SmartCore::Types::Primitive::Factory::RuntimeTypeBuilder
|
6
|
+
class << self
|
7
|
+
# @param type_name [String, Symbol]
|
8
|
+
# @param type_category [Class<SmartCore::Types::Primitive>]
|
9
|
+
# @param runtime_attributes [Array<Any>]
|
10
|
+
# @return [SmartCore::Types::Primitive]
|
11
|
+
#
|
12
|
+
# @api private
|
13
|
+
# @since 0.3.0
|
14
|
+
def build_with_runtime(type_name, type_category, runtime_attributes)
|
15
|
+
type = type_category.const_get(type_name)
|
16
|
+
type.runtime_attributes_checker.check!(runtime_attributes)
|
17
|
+
|
18
|
+
type.clone.tap do |type_with_custom_runtime|
|
19
|
+
type_with_custom_runtime.instance_variable_set(
|
20
|
+
:@runtime_attributes, runtime_attributes.freeze
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# @param new_instance [SmartCore::Types::Primitive]
|
26
|
+
# @param cloneable_instance [SmartCore::Types::Primitive]
|
27
|
+
# @return [void]
|
28
|
+
#
|
29
|
+
# @api private
|
30
|
+
# @since 0.3.0
|
31
|
+
# rubocop:disable Metrics/AbcSize, Layout/LineLength
|
32
|
+
def initialize_clone(new_instance, cloneable_instance)
|
33
|
+
name_clone = cloneable_instance.instance_variable_get(:@name)
|
34
|
+
category_clone = cloneable_instance.instance_variable_get(:@category)
|
35
|
+
validator_clone = cloneable_instance.instance_variable_get(:@validator).___copy_for___(new_instance)
|
36
|
+
caster_clone = cloneable_instance.instance_variable_get(:@caster)
|
37
|
+
runtime_attributes_clone = cloneable_instance.instance_variable_get(:@runtime_attributes).clone
|
38
|
+
runtime_attributes_checker_clone = cloneable_instance.instance_variable_get(:@runtime_attributes_checker).___copy_for___(new_instance)
|
39
|
+
lock_clone = SmartCore::Engine::Lock.new
|
40
|
+
nilable_clone = nil
|
41
|
+
|
42
|
+
new_instance.instance_variable_set(:@name, name_clone)
|
43
|
+
new_instance.instance_variable_set(:@category, category_clone)
|
44
|
+
new_instance.instance_variable_set(:@validator, validator_clone)
|
45
|
+
new_instance.instance_variable_set(:@caster, caster_clone)
|
46
|
+
new_instance.instance_variable_set(:@runtime_attributes, runtime_attributes_clone)
|
47
|
+
new_instance.instance_variable_set(:@runtime_attributes_checker, runtime_attributes_checker_clone)
|
48
|
+
new_instance.instance_variable_set(:@lock_clone, lock_clone)
|
49
|
+
new_instance.instance_variable_set(:@nilable, nilable_clone)
|
50
|
+
end
|
51
|
+
# rubocop:enable Metrics/AbcSize, Layout/LineLength
|
52
|
+
end
|
53
|
+
end
|
@@ -2,8 +2,10 @@
|
|
2
2
|
|
3
3
|
# @api private
|
4
4
|
# @since 0.1.0
|
5
|
+
# @version 0.3.0
|
5
6
|
class SmartCore::Types::Primitive::Factory
|
6
7
|
require_relative 'factory/definition_context'
|
8
|
+
require_relative 'factory/runtime_type_builder'
|
7
9
|
|
8
10
|
class << self
|
9
11
|
# @param type_category [Class<SmartCore::Types::Primitive>]
|
@@ -13,12 +15,26 @@ class SmartCore::Types::Primitive::Factory
|
|
13
15
|
#
|
14
16
|
# @api private
|
15
17
|
# @since 0.1.0
|
18
|
+
# @version 0.3.0
|
16
19
|
def create_type(type_category, type_name, type_definition)
|
17
20
|
type_definitions = build_type_definitions(type_definition)
|
21
|
+
type_runtime_attributes_checker = build_type_runtime_attributes_checker(type_definitions)
|
18
22
|
type_checker = build_type_checker(type_definitions)
|
19
23
|
type_caster = build_type_caster(type_definitions)
|
20
|
-
|
21
|
-
|
24
|
+
type_invariant_control = build_type_invariant_control(type_definitions)
|
25
|
+
type_validator = build_type_validator(type_checker, type_invariant_control)
|
26
|
+
build_type(
|
27
|
+
type_category,
|
28
|
+
type_name,
|
29
|
+
type_validator,
|
30
|
+
type_caster,
|
31
|
+
type_runtime_attributes_checker
|
32
|
+
).tap do |type|
|
33
|
+
assign_type_validator(type, type_validator)
|
34
|
+
assign_type_runtime_attributes_checker(type, type_runtime_attributes_checker)
|
35
|
+
register_new_type(type_category, type_name, type)
|
36
|
+
register_runtime_type_builder(type_category, type_name)
|
37
|
+
end
|
22
38
|
end
|
23
39
|
|
24
40
|
private
|
@@ -38,10 +54,33 @@ class SmartCore::Types::Primitive::Factory
|
|
38
54
|
raise(
|
39
55
|
SmartCore::Types::NoCheckerDefinitionError,
|
40
56
|
'Type checker is not provided. You should define it via .define_checker(&block)'
|
41
|
-
) if context.type_checker
|
57
|
+
) if context.type_checker == nil
|
42
58
|
end
|
43
59
|
end
|
44
60
|
|
61
|
+
# @param type_definitions [SmartCore::Types::Primitive::Factory::DefinitionContext]
|
62
|
+
# @return [SmartCore::Types::Primitive::RuntimeAttributesChecker]
|
63
|
+
#
|
64
|
+
# @api private
|
65
|
+
# @since 0.3.0
|
66
|
+
def build_type_runtime_attributes_checker(type_definitions)
|
67
|
+
SmartCore::Types::Primitive::RuntimeAttributesChecker.new(
|
68
|
+
type_definitions.type_runtime_attributes_checker
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
# @param type_definitions [SmartCore::Types::Primitive::Factory::DefinitionContext]
|
73
|
+
# @return [SmartCore::Types::Primitive::InvariantControl]
|
74
|
+
#
|
75
|
+
# @api private
|
76
|
+
# @since 0.2.0
|
77
|
+
def build_type_invariant_control(type_definitions)
|
78
|
+
SmartCore::Types::Primitive::InvariantControl.create(
|
79
|
+
type_definitions.type_invariant_chains,
|
80
|
+
type_definitions.type_invariants
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
45
84
|
# @param type_definitions [SmartCore::Types::Primitive::Factory::DefinitionContext]
|
46
85
|
# @return [SmartCore::Types::Primitive::Checker]
|
47
86
|
#
|
@@ -57,23 +96,67 @@ class SmartCore::Types::Primitive::Factory
|
|
57
96
|
# @api private
|
58
97
|
# @since 0.1.0
|
59
98
|
def build_type_caster(type_definitions)
|
60
|
-
if type_definitions.type_caster
|
99
|
+
if type_definitions.type_caster == nil
|
61
100
|
SmartCore::Types::Primitive::UndefinedCaster.new
|
62
101
|
else
|
63
102
|
SmartCore::Types::Primitive::Caster.new(type_definitions.type_caster)
|
64
103
|
end
|
65
104
|
end
|
66
105
|
|
106
|
+
# @param checker [SmartCore::Types::Primitive::Checker]
|
107
|
+
# @param invariant_control [SmartCore::Types::Primitive::InvariantControl]
|
108
|
+
# @return [void]
|
109
|
+
#
|
110
|
+
# @api private
|
111
|
+
# @since 0.2.0
|
112
|
+
def build_type_validator(type_checker, type_invariant_control)
|
113
|
+
SmartCore::Types::Primitive::Validator.new(type_checker, type_invariant_control)
|
114
|
+
end
|
115
|
+
|
67
116
|
# @param type_klass [Class<SmartCore::Types::Primitive>]
|
68
117
|
# @param type_name [String, Symbol]
|
69
|
-
# @param
|
118
|
+
# @param type_validator [SmartCore::Types::Primitive::Validator]
|
70
119
|
# @param type_caster [SmartCore::Types::Primitive::Caster]
|
120
|
+
# @param type_runtime_attributes_checker [SmartCore::Types::Primitive::RuntimeAttributesChecker]
|
71
121
|
# @return [SmartCore::Types::Primitive]
|
72
122
|
#
|
73
123
|
# @api private
|
74
124
|
# @since 0.1.0
|
75
|
-
|
76
|
-
|
125
|
+
# @version 0.3.0
|
126
|
+
def build_type(
|
127
|
+
type_category,
|
128
|
+
type_name,
|
129
|
+
type_validator,
|
130
|
+
type_caster,
|
131
|
+
type_runtime_attributes_checker
|
132
|
+
)
|
133
|
+
Class.new(type_category).new(
|
134
|
+
type_name,
|
135
|
+
type_category,
|
136
|
+
type_validator,
|
137
|
+
type_caster,
|
138
|
+
type_runtime_attributes_checker
|
139
|
+
)
|
140
|
+
end
|
141
|
+
|
142
|
+
# @param type [SmartCore::Types::Primitive]
|
143
|
+
# @param type_validator [SmartCore::Types::Primitive::Validator]
|
144
|
+
# @return [void]
|
145
|
+
#
|
146
|
+
# @api private
|
147
|
+
# @since 0.2.0
|
148
|
+
def assign_type_validator(type, type_validator)
|
149
|
+
type_validator.___assign_type___(type)
|
150
|
+
end
|
151
|
+
|
152
|
+
# @param type [SmartCore::Types::Primitive]
|
153
|
+
# @param type_runtime_attributes_checker [SmartCore::Types::Primitive::RuntimeAttributesChecker]
|
154
|
+
# @return [void]
|
155
|
+
#
|
156
|
+
# @api private
|
157
|
+
# @since 0.3.0
|
158
|
+
def assign_type_runtime_attributes_checker(type, type_runtime_attributes_checker)
|
159
|
+
type_runtime_attributes_checker.___assign_type___(type)
|
77
160
|
end
|
78
161
|
|
79
162
|
# @param type_category [Class<SmartCore::Types::Primitive>]
|
@@ -93,5 +176,19 @@ class SmartCore::Types::Primitive::Factory
|
|
93
176
|
"Incorrect constant name for new type (#{type_name})"
|
94
177
|
)
|
95
178
|
end
|
179
|
+
|
180
|
+
# @param type_category [Class<SmartCore::Types::Primitive>]
|
181
|
+
# @param type_name [String, Symbol]
|
182
|
+
# @return [void]
|
183
|
+
#
|
184
|
+
# @raise [SmartCore::Types::IncorrectTypeNameError]
|
185
|
+
#
|
186
|
+
# @api private
|
187
|
+
# @since 0.3.0
|
188
|
+
def register_runtime_type_builder(type_category, type_name)
|
189
|
+
type_category.define_singleton_method(type_name) do |*runtime_attributes|
|
190
|
+
RuntimeTypeBuilder.build_with_runtime(type_name, type_category, runtime_attributes)
|
191
|
+
end
|
192
|
+
end
|
96
193
|
end
|
97
194
|
end
|