smart_schema 0.12.1 → 0.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +12 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +20 -0
  5. data/CHANGELOG.md +106 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +5 -0
  8. data/Gemfile.lock +266 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +305 -0
  11. data/Rakefile +21 -0
  12. data/bin/console +8 -0
  13. data/bin/setup +8 -0
  14. data/lib/smart_core/schema/checker/reconciler/constructor.rb +60 -0
  15. data/lib/smart_core/schema/checker/reconciler/matcher/options.rb +33 -0
  16. data/lib/smart_core/schema/checker/reconciler/matcher/result.rb +87 -0
  17. data/lib/smart_core/schema/checker/reconciler/matcher/result_finalizer.rb +186 -0
  18. data/lib/smart_core/schema/checker/reconciler/matcher.rb +62 -0
  19. data/lib/smart_core/schema/checker/reconciler.rb +106 -0
  20. data/lib/smart_core/schema/checker/rules/base.rb +110 -0
  21. data/lib/smart_core/schema/checker/rules/extra_keys/failure.rb +24 -0
  22. data/lib/smart_core/schema/checker/rules/extra_keys/result.rb +37 -0
  23. data/lib/smart_core/schema/checker/rules/extra_keys/success.rb +30 -0
  24. data/lib/smart_core/schema/checker/rules/extra_keys.rb +31 -0
  25. data/lib/smart_core/schema/checker/rules/optional.rb +27 -0
  26. data/lib/smart_core/schema/checker/rules/options/empty.rb +43 -0
  27. data/lib/smart_core/schema/checker/rules/options/filled.rb +49 -0
  28. data/lib/smart_core/schema/checker/rules/options/type.rb +88 -0
  29. data/lib/smart_core/schema/checker/rules/options.rb +60 -0
  30. data/lib/smart_core/schema/checker/rules/required.rb +27 -0
  31. data/lib/smart_core/schema/checker/rules/requirement/optional.rb +36 -0
  32. data/lib/smart_core/schema/checker/rules/requirement/required.rb +36 -0
  33. data/lib/smart_core/schema/checker/rules/requirement/result.rb +95 -0
  34. data/lib/smart_core/schema/checker/rules/requirement.rb +9 -0
  35. data/lib/smart_core/schema/checker/rules/result/base.rb +44 -0
  36. data/lib/smart_core/schema/checker/rules/result/failure.rb +41 -0
  37. data/lib/smart_core/schema/checker/rules/result/success.rb +15 -0
  38. data/lib/smart_core/schema/checker/rules/result.rb +9 -0
  39. data/lib/smart_core/schema/checker/rules/type_aliases.rb +57 -0
  40. data/lib/smart_core/schema/checker/rules/verifier/result.rb +75 -0
  41. data/lib/smart_core/schema/checker/rules/verifier.rb +74 -0
  42. data/lib/smart_core/schema/checker/rules.rb +89 -0
  43. data/lib/smart_core/schema/checker/verifiable_hash.rb +65 -0
  44. data/lib/smart_core/schema/checker.rb +106 -0
  45. data/lib/smart_core/schema/configuration.rb +33 -0
  46. data/lib/smart_core/schema/dsl.rb +81 -0
  47. data/lib/smart_core/schema/errors.rb +65 -0
  48. data/lib/smart_core/schema/key_control.rb +39 -0
  49. data/lib/smart_core/schema/plugins/abstract.rb +55 -0
  50. data/lib/smart_core/schema/plugins/access_mixin.rb +47 -0
  51. data/lib/smart_core/schema/plugins/dry_types/dry_types/abstract_factory.rb +99 -0
  52. data/lib/smart_core/schema/plugins/dry_types/dry_types/operation/base.rb +9 -0
  53. data/lib/smart_core/schema/plugins/dry_types/dry_types/operation/cast.rb +21 -0
  54. data/lib/smart_core/schema/plugins/dry_types/dry_types/operation/valid.rb +16 -0
  55. data/lib/smart_core/schema/plugins/dry_types/dry_types/operation/validate.rb +19 -0
  56. data/lib/smart_core/schema/plugins/dry_types/dry_types/operation.rb +12 -0
  57. data/lib/smart_core/schema/plugins/dry_types/dry_types.rb +10 -0
  58. data/lib/smart_core/schema/plugins/dry_types/errors.rb +13 -0
  59. data/lib/smart_core/schema/plugins/dry_types.rb +27 -0
  60. data/lib/smart_core/schema/plugins/registry.rb +158 -0
  61. data/lib/smart_core/schema/plugins/registry_interface.rb +63 -0
  62. data/lib/smart_core/schema/plugins.rb +17 -0
  63. data/lib/smart_core/schema/result.rb +62 -0
  64. data/lib/smart_core/schema/type_system/interop/abstract_factory.rb +92 -0
  65. data/lib/smart_core/schema/type_system/interop/aliasing/alias_list.rb +131 -0
  66. data/lib/smart_core/schema/type_system/interop/aliasing.rb +72 -0
  67. data/lib/smart_core/schema/type_system/interop/operation.rb +30 -0
  68. data/lib/smart_core/schema/type_system/interop.rb +128 -0
  69. data/lib/smart_core/schema/type_system/registry.rb +162 -0
  70. data/lib/smart_core/schema/type_system/registry_interface.rb +87 -0
  71. data/lib/smart_core/schema/type_system/smart_types/abstract_factory.rb +99 -0
  72. data/lib/smart_core/schema/type_system/smart_types/operation/base.rb +8 -0
  73. data/lib/smart_core/schema/type_system/smart_types/operation/cast.rb +16 -0
  74. data/lib/smart_core/schema/type_system/smart_types/operation/valid.rb +16 -0
  75. data/lib/smart_core/schema/type_system/smart_types/operation/validate.rb +16 -0
  76. data/lib/smart_core/schema/type_system/smart_types/operation.rb +13 -0
  77. data/lib/smart_core/schema/type_system/smart_types.rb +48 -0
  78. data/lib/smart_core/schema/type_system.rb +16 -0
  79. data/lib/smart_core/schema/version.rb +14 -0
  80. data/lib/smart_core/schema.rb +67 -0
  81. data/smart_schema.gemspec +46 -0
  82. metadata +83 -3
@@ -0,0 +1,131 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 0.12.0
5
+ class SmartCore::Schema::TypeSystem::Interop::Aliasing::AliasList
6
+ # @param interop_klass [Class<SmartCore::Schema::TypeSystem::Interop>]
7
+ # @return [void]
8
+ #
9
+ # @api private
10
+ # @since 0.12.0
11
+ def initialize(interop_klass)
12
+ @interop_klass = interop_klass
13
+ @list = {}
14
+ @lock = SmartCore::Engine::ReadWriteLock.new
15
+ end
16
+
17
+ # @return [Array<String>]
18
+ #
19
+ # @api private
20
+ # @since 0.12.0
21
+ def keys
22
+ @lock.read_sync { registered_aliases }
23
+ end
24
+
25
+ # @return [Hash<String,Any>]
26
+ #
27
+ # @api private
28
+ # @since 0.12.0
29
+ def to_h
30
+ @lock.read_sync { transform_to_hash }
31
+ end
32
+ alias_method :to_hash, :to_h
33
+
34
+ # @param alias_name [String, Symbol]
35
+ # @param type [Any]
36
+ # @return [void]
37
+ #
38
+ # @api private
39
+ # @since 0.12.0
40
+ def associate(alias_name, type)
41
+ interop_klass.prevent_incompatible_type!(type)
42
+ @lock.write_sync { set_alias(alias_name, type) }
43
+ end
44
+
45
+ # @param alias_name [String, Symbol]
46
+ # @return [Any]
47
+ #
48
+ # @api private
49
+ # @since 0.12.0
50
+ def resolve(alias_name)
51
+ @lock.read_sync { get_alias(alias_name) }
52
+ end
53
+
54
+ private
55
+
56
+ # @return [Hash<String,Any>]
57
+ #
58
+ # @api private
59
+ # @since 0.12.0
60
+ attr_reader :list
61
+
62
+ # @return [Class<SmartCore::Schema::TypeSystem::Interop>]
63
+ #
64
+ # @api private
65
+ # @since 0.12.0
66
+ attr_reader :interop_klass
67
+
68
+ # @param alias_name [String, Symbol]
69
+ # @param type [Any]
70
+ # @return [void]
71
+ #
72
+ # @api private
73
+ # @since 0.12.0
74
+ def set_alias(alias_name, type)
75
+ alias_name = normalized_alias(alias_name)
76
+
77
+ if list.key?(alias_name)
78
+ ::Warning.warn(
79
+ "[#{interop_klass.name}] Shadowing of the already existing \"#{alias_name}\" type alias."
80
+ )
81
+ end
82
+
83
+ list[alias_name] = type
84
+ end
85
+
86
+ # @param alias_name [String, Symbol]
87
+ # @return [Any]
88
+ #
89
+ # @api private
90
+ # @since 0.12.0
91
+ def get_alias(alias_name)
92
+ alias_name = normalized_alias(alias_name)
93
+
94
+ raise(
95
+ SmartCore::Schema::TypeAliasNotFoundError,
96
+ "Alias with name `#{alias_name}` not found."
97
+ ) unless list.key?(alias_name)
98
+
99
+ list.fetch(alias_name)
100
+ end
101
+
102
+ # @param alias_name [String, Symbol]
103
+ # @return [String]
104
+ #
105
+ # @api private
106
+ # @since 0.12.0
107
+ def normalized_alias(alias_name)
108
+ raise(
109
+ SmartCore::Schema::ArgumentError,
110
+ 'Type alias should be a type of string or symbol'
111
+ ) unless alias_name.is_a?(String) || alias_name.is_a?(Symbol)
112
+
113
+ alias_name.to_s
114
+ end
115
+
116
+ # @return [Hash<String,Any>]
117
+ #
118
+ # @api private
119
+ # @since 0.12.0
120
+ def transform_to_hash
121
+ list.to_h
122
+ end
123
+
124
+ # @return [Array<String>]
125
+ #
126
+ # @api private
127
+ # @since 0.12.0
128
+ def registered_aliases
129
+ list.keys
130
+ end
131
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @version 0.12.0
5
+ module SmartCore::Schema::TypeSystem::Interop::Aliasing
6
+ require_relative 'aliasing/alias_list'
7
+
8
+ class << self
9
+ # @param base_klass [Class]
10
+ # @return [void]
11
+ #
12
+ # @api private
13
+ # @version 0.12.0
14
+ def included(base_klass)
15
+ base_klass.extend(ClassMethods)
16
+ base_klass.singleton_class.prepend(ClassInheritance)
17
+ end
18
+ end
19
+
20
+ # @api private
21
+ # @version 0.12.0
22
+ module ClassInheritance
23
+ # @param child_klass [Class<SmartCore::Schema::TypeSystem::Interop>]
24
+ # @return [void]
25
+ #
26
+ # @api private
27
+ # @version 0.12.0
28
+ def inherited(child_klass)
29
+ child_klass.instance_variable_set(:@__type_aliases__, AliasList.new(child_klass))
30
+ super
31
+ end
32
+ end
33
+
34
+ # @api private
35
+ # @version 0.12.0
36
+ module ClassMethods
37
+ # @return [SmartCore::Schema::TypeSystem::Interop::Aliasing::AliasList]
38
+ #
39
+ # @api private
40
+ # @version 0.12.0
41
+ def __type_aliases__
42
+ @__type_aliases__
43
+ end
44
+
45
+ # @return [Array<String>]
46
+ #
47
+ # @api public
48
+ # @version 0.12.0
49
+ def type_aliases
50
+ __type_aliases__.keys
51
+ end
52
+
53
+ # @param alias_name [String, Symbol]
54
+ # @param type [Any]
55
+ # @return [void]
56
+ #
57
+ # @api public
58
+ # @version 0.12.0
59
+ def type_alias(alias_name, type)
60
+ __type_aliases__.associate(alias_name, type)
61
+ end
62
+
63
+ # @param alias_name [String, Symbol]
64
+ # @return [Any]
65
+ #
66
+ # @api public
67
+ # @version 0.12.0
68
+ def type_from_alias(alias_name)
69
+ __type_aliases__.resolve(alias_name)
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @abstract
4
+ # @api private
5
+ # @since 0.12.0
6
+ class SmartCore::Schema::TypeSystem::Interop::Operation
7
+ # @param type [Any]
8
+ # @return [void]
9
+ #
10
+ # @api private
11
+ # @since 0.12.0
12
+ def initialize(type)
13
+ @type = type
14
+ end
15
+
16
+ # @param value [Any]
17
+ # @return [Any]
18
+ #
19
+ # @api private
20
+ # @since 0.12.0
21
+ def call(value); end
22
+
23
+ private
24
+
25
+ # @return [Any]
26
+ #
27
+ # @api private
28
+ # @since 0.12.0
29
+ attr_reader :type
30
+ end
@@ -0,0 +1,128 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @abstract
4
+ # @api private
5
+ # @since 0.12.0
6
+ class SmartCore::Schema::TypeSystem::Interop
7
+ require_relative 'interop/operation'
8
+ require_relative 'interop/abstract_factory'
9
+ require_relative 'interop/aliasing'
10
+
11
+ # @since 0.12.0
12
+ include SmartCore::Schema::TypeSystem::Interop::Aliasing
13
+
14
+ class << self
15
+ # @param type_object [Any]
16
+ # @return [SmartCore::Schema::TypeSystem::Interop]
17
+ #
18
+ # @api private
19
+ # @since 0.12.0
20
+ def create(type_object)
21
+ self::AbstractFactory.create(type_object)
22
+ end
23
+
24
+ # @return [SmartCore::Schema::TypeSystem::Interop]
25
+ #
26
+ # @api private
27
+ # @since 0.12.0
28
+ def generic_type_object
29
+ self::AbstractFactory.generic_type_object
30
+ end
31
+
32
+ # @param type_object [Any]
33
+ # @return [void]
34
+ #
35
+ # @raise [SmartCore::Schema::IncorrectTypeObjectError]
36
+ #
37
+ # @api private
38
+ # @since 0.12.0
39
+ def prevent_incompatible_type!(type_object)
40
+ self::AbstractFactory.prevent_incompatible_type!(type_object)
41
+ end
42
+
43
+ # @return [Any]
44
+ #
45
+ # @api private
46
+ # @since 0.12.0
47
+ def primitive_type_class
48
+ self::AbstractFactory.primitive_type_class
49
+ end
50
+
51
+ # @return [Any]
52
+ #
53
+ # @api private
54
+ # @since 0.12.1
55
+ def hash_type_object_for_nested_schemas
56
+ self::AbstractFactory.hash_type_object_for_nested_schemas
57
+ end
58
+ end
59
+
60
+ # @return [String]
61
+ #
62
+ # @api private
63
+ # @since 0.5.1
64
+ attr_reader :identifier
65
+
66
+ # @param identifier [String]
67
+ # @param valid_op [SmartCore::Schema::TypeSystem::Interop::Operation]
68
+ # @param validate_op [SmartCore::Schema::TypeSystem::Interop::Operation]
69
+ # @param cast_op [SmartCore::Schema::TypeSystem::Interop::Operation]
70
+ # @return [void]
71
+ #
72
+ # @api private
73
+ # @since 0.12.0
74
+ # @version 0.5.1
75
+ def initialize(identifier, valid_op, validate_op, cast_op)
76
+ @identifier = identifier
77
+ @valid_op = valid_op
78
+ @validate_op = validate_op
79
+ @cast_op = cast_op
80
+ end
81
+
82
+ # @param value [Any]
83
+ # @return [Boolean]
84
+ #
85
+ # @api private
86
+ # @since 0.12.0
87
+ def valid?(value)
88
+ valid_op.call(value)
89
+ end
90
+
91
+ # @param value [Any]
92
+ # @return [void]
93
+ #
94
+ # @api private
95
+ # @since 0.12.0
96
+ def validate!(value)
97
+ validate_op.call(value)
98
+ end
99
+
100
+ # @param value [Any]
101
+ # @return [Any]
102
+ #
103
+ # @api private
104
+ # @since 0.12.0
105
+ def cast(value)
106
+ cast_op.call(value)
107
+ end
108
+
109
+ private
110
+
111
+ # @return [SmartCore::Schema::TypeSystem::Interop::Operation]
112
+ #
113
+ # @api private
114
+ # @since 0.12.0
115
+ attr_reader :valid_op
116
+
117
+ # @return [SmartCore::Schema::TypeSystem::Interop::Operation]
118
+ #
119
+ # @api private
120
+ # @since 0.12.0
121
+ attr_reader :validate_op
122
+
123
+ # @return [SmartCore::Schema::TypeSystem::Interop::Operation]
124
+ #
125
+ # @api private
126
+ # @since 0.12.0
127
+ attr_reader :cast_op
128
+ end
@@ -0,0 +1,162 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 0.12.0
5
+ class SmartCore::Schema::TypeSystem::Registry
6
+ include Enumerable
7
+
8
+ # @return [void]
9
+ #
10
+ # @api private
11
+ # @since 0.12.0
12
+ def initialize
13
+ @systems = {}
14
+ @lock = SmartCore::Engine::ReadWriteLock.new
15
+ end
16
+
17
+ # @param system_identifier [String, Symbol]
18
+ # @param interop_klass [Class<SmartCore::Schema::TypeSystem::Interop>]
19
+ # @return [void]
20
+ #
21
+ # @api private
22
+ # @since 0.12.0
23
+ def register(system_identifier, interop_klass)
24
+ @lock.write_sync { apply(system_identifier, interop_klass) }
25
+ end
26
+
27
+ # @param system_identifier [String, Symbol]
28
+ # @return [Class<SmartCore::Schema::TypeSystem::Interop>]
29
+ #
30
+ # @api private
31
+ # @since 0.12.0
32
+ def resolve(system_identifier)
33
+ @lock.read_sync { fetch(system_identifier) }
34
+ end
35
+
36
+ # @return [Array<String>]
37
+ #
38
+ # @api private
39
+ # @since 0.12.0
40
+ def names
41
+ @lock.read_sync { system_names }
42
+ end
43
+
44
+ # @return [Array<Class<SmartCore::Schema::TypeSystem::Interop>>]
45
+ #
46
+ # @api private
47
+ # @since 0.12.0
48
+ def interops
49
+ @lock.read_sync { system_interops }
50
+ end
51
+
52
+ # @param block [Block]
53
+ # @yield [system_name, system_interop]
54
+ # @yieldparam system_name [String]
55
+ # @yieldparam system_interop [Class<SmartCore::Schema::TypeSystem::Interop>]
56
+ # @return [Enumerable]
57
+ #
58
+ # @api private
59
+ # @since 0.12.0
60
+ def each(&block)
61
+ @lock.read_sync { iterate(&block) }
62
+ end
63
+
64
+ # @return [Hash<String,Class<SmartCore::Schema::TypeSystem::Interop>]
65
+ #
66
+ # @api private
67
+ # @since 0.12.0
68
+ def to_h
69
+ @lock.write_sync { systems.dup }
70
+ end
71
+ alias_method :to_hash, :to_h
72
+
73
+ private
74
+
75
+ # @return [Hash<String,Class<SmartCore::Schema::TypeSystem::Interop>]
76
+ #
77
+ # @api private
78
+ # @since 0.12.0
79
+ attr_reader :systems
80
+
81
+ # @return [Array<String>]
82
+ #
83
+ # @pai private
84
+ def system_names
85
+ systems.keys
86
+ end
87
+
88
+ # @return [Array<Class<SmartCore::Schema::TypeSystem::Interop>>]
89
+ #
90
+ # @api private
91
+ # @since 0.12.0
92
+ def system_interops
93
+ systems.values
94
+ end
95
+
96
+ # @param block [Block]
97
+ # @yield [system_name, system_interop]
98
+ # @yieldparam system_name [String]
99
+ # @yieldparam system_interop [Class<SmartCore::Schema::TypeSystem::Interop>]
100
+ # @return [Enumerable]
101
+ #
102
+ # @api private
103
+ # @since 0.12.0
104
+ def iterate(&block)
105
+ block_given? ? systems.each_pair(&block) : systems.each_pair
106
+ end
107
+
108
+ # @param system_identifier [String, Symbol]
109
+ # @param interop_klass [Class<SmartCore::Schema::TypeSystem::Interop>]
110
+ # @return [void]
111
+ #
112
+ # @api private
113
+ # @since 0.12.0
114
+ def apply(system_identifier, interop_klass)
115
+ prevent_incorrect_system_interop!(interop_klass)
116
+ identifier = indifferently_accessible_identifier(system_identifier)
117
+ systems[identifier] = interop_klass
118
+ end
119
+
120
+ # @param system_identifier [String, Symbol]
121
+ # @return [Class<SmartCore::Schema::TypeSystem::Interop>]
122
+ #
123
+ # @raise [SmartCore::Schema::UnsupportedTypeSystemError]
124
+ #
125
+ # @api private
126
+ # @since 0.12.0
127
+ def fetch(system_identifier)
128
+ identifier = indifferently_accessible_identifier(system_identifier)
129
+
130
+ raise(
131
+ SmartCore::Schema::UnsupportedTypeSystemError,
132
+ "`#{identifier}` type system is not supported."
133
+ ) unless systems.key?(identifier)
134
+
135
+ systems.fetch(identifier)
136
+ end
137
+
138
+ # @param interop_klass [Class<SMartCore::Schema::TypeSystem::Interop>]
139
+ # @return [void]
140
+ #
141
+ # @raise [SmartCore::Schema::IncorrectTypeSystemInteropError]
142
+ #
143
+ # @api private
144
+ # @since 0.12.0
145
+ def prevent_incorrect_system_interop!(interop_klass)
146
+ unless interop_klass.is_a?(Class) && interop_klass < SmartCore::Schema::TypeSystem::Interop
147
+ raise(
148
+ SmartCore::Schema::IncorrectTypeSystemInteropError,
149
+ 'Incorrect type system interop class.'
150
+ )
151
+ end
152
+ end
153
+
154
+ # @param system_identifier [String, Symbol]
155
+ # @return [String]
156
+ #
157
+ # @api private
158
+ # @since 0.12.0
159
+ def indifferently_accessible_identifier(system_identifier)
160
+ system_identifier.to_s.clone.tap(&:freeze)
161
+ end
162
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 0.12.0
5
+ module SmartCore::Schema::TypeSystem::RegistryInterface
6
+ class << self
7
+ # @param base_module [Class, Module]
8
+ # @return [void]
9
+ #
10
+ # @api private
11
+ # @since 0.12.0
12
+ def extended(base_module)
13
+ base_module.instance_variable_set(
14
+ :@registry, SmartCore::Schema::TypeSystem::Registry.new
15
+ )
16
+ base_module.instance_variable_set(
17
+ :@access_lock, SmartCore::Engine::ReadWriteLock.new
18
+ )
19
+ end
20
+ end
21
+
22
+ # @option system_identifier [String, Symbol]
23
+ # @option type [Any]
24
+ # @return [SmartCore::Schema::TypeSystem::Interop]
25
+ #
26
+ # @api private
27
+ # @since 0.12.0
28
+ def build_interop(system: system_identifier, type: type_object)
29
+ @access_lock.read_sync { registry.resolve(system_identifier).create(type_object) }
30
+ end
31
+
32
+ # @param identifier [String, Symbol]
33
+ # @param interop_klass [Class<SmartCore::Schema::TypeSystem::Interop>]
34
+ # @return [void]
35
+ #
36
+ # @api private
37
+ # @since 0.12.0
38
+ def register(identifier, interop_klass)
39
+ @access_lock.write_sync { registry.register(identifier, interop_klass) }
40
+ end
41
+
42
+ # @param identifier [String, Symbol]
43
+ # @return [Class<SmartCore::Schema::TypeSystem::Interop>]
44
+ #
45
+ # @api private
46
+ # @since 0.12.0
47
+ def resolve(identifier)
48
+ @access_lock.read_sync { registry.resolve(identifier) }
49
+ end
50
+ alias_method :[], :resolve
51
+
52
+ # @return [Array<String>]
53
+ #
54
+ # @api public
55
+ # @since 0.12.0
56
+ def names
57
+ @access_lock.read_sync { registry.names }
58
+ end
59
+
60
+ # @return [Array<Class<SmartCore::Schema::TypeSystem::Interop>>]
61
+ #
62
+ # @api public
63
+ # @since 0.12.0
64
+ def systems
65
+ @access_lock.read_sync { registry.to_h }
66
+ end
67
+
68
+ # @param block [Block]
69
+ # @yield [system_name, system_interop]
70
+ # @yieldparam system_name [String]
71
+ # @yieldparam system_interop [Class<SmartCore::Schema::TypeSystem::Interop>]
72
+ # @return [Enumerable]
73
+ #
74
+ # @api public
75
+ # @since 0.12.0
76
+ def each(&block)
77
+ @access_lock.read_sync { registry.each(&block) }
78
+ end
79
+
80
+ private
81
+
82
+ # @return [SmartCore::Schema::TypeSystem::Registry]
83
+ #
84
+ # @api private
85
+ # @since 0.12.0
86
+ attr_reader :registry
87
+ end
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SmartCore::Schema::TypeSystem
4
+ # @api private
5
+ # @since 0.12.0
6
+ class SmartTypes::AbstractFactory < Interop::AbstractFactory
7
+ class << self
8
+ # @param type [SmartCore::Types::Primitive]
9
+ # @return [void]
10
+ #
11
+ # @raise [SmartCore::Schema::IncorrectTypeObjectError]
12
+ #
13
+ # @api private
14
+ # @since 0.12.0
15
+ def prevent_incompatible_type!(type)
16
+ unless type.is_a?(SmartCore::Types::Primitive)
17
+ raise(
18
+ SmartCore::Schema::IncorrectTypeObjectError,
19
+ 'Incorrect SmartCore::Types primitive ' \
20
+ '(type object should be a type of SmartCore::Types::Primitive)'
21
+ )
22
+ end
23
+ end
24
+
25
+ # @param type [Any]
26
+ # @return [String]
27
+ #
28
+ # @api private
29
+ # @since 0.12.0
30
+ def build_identifier(type)
31
+ type.name
32
+ end
33
+
34
+ # @param type [SmartCore::Types::Primitive]
35
+ # @return [SmartCore::Schema::TypeSystem::SmartTypes::Operation::Valid]
36
+ #
37
+ # @api private
38
+ # @since 0.12.0
39
+ def build_valid_operation(type)
40
+ SmartTypes::Operation::Valid.new(type)
41
+ end
42
+
43
+ # @return [SmartCore::Types::Value::Any]
44
+ #
45
+ # @api private
46
+ # @since 0.12.0
47
+ def generic_type_object
48
+ SmartCore::Types::Value::Any
49
+ end
50
+
51
+ # @return [SmartCore::Types::Primitive]
52
+ #
53
+ # @api private
54
+ # @since 0.12.0
55
+ def primitive_type_class
56
+ SmartCore::Types::Primitive
57
+ end
58
+
59
+ # @return [SmartCore::Types::Value::Hash]
60
+ #
61
+ # @api private
62
+ # @since 0.12.1
63
+ def hash_type_object_for_nested_schemas
64
+ SmartCore::Types::Value::Hash
65
+ end
66
+
67
+ # @param type [SmartCore::Types::Primitive]
68
+ # @return [SmartCore::Schema::TypeSystem::SmartTypes::Operation::Validate]
69
+ #
70
+ # @api private
71
+ # @since 0.12.0
72
+ def build_validate_operation(type)
73
+ SmartTypes::Operation::Validate.new(type)
74
+ end
75
+
76
+ # @param type [SmartCore::Types::Primitive]
77
+ # @return [SmartCore::Schema::TypeSystem::SmartTypes::Operation::Cast]
78
+ #
79
+ # @api private
80
+ # @since 0.12.0
81
+ def build_cast_operation(type)
82
+ SmartTypes::Operation::Cast.new(type)
83
+ end
84
+
85
+ # @param identifier [String]
86
+ # @param valid_op [SmartCore::Schema::TypeSystem::SmartTypes::Operation::Valid]
87
+ # @param valid_op [SmartCore::Schema::TypeSystem::SmartTypes::Operation::Validate]
88
+ # @param valid_op [SmartCore::Schema::TypeSystem::SmartTypes::Operation::Cast]
89
+ # @return [SmartCore::Schema::TypeSystem::SmartTypes]
90
+ #
91
+ # @api private
92
+ # @since 0.12.0
93
+ # @version 0.5.1
94
+ def build_interop(identifier, valid_op, validate_op, cast_op)
95
+ SmartTypes.new(identifier, valid_op, validate_op, cast_op)
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SmartCore::Schema::TypeSystem
4
+ # @api private
5
+ # @since 0.12.0
6
+ class SmartTypes::Operation::Base < Interop::Operation
7
+ end
8
+ end