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,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SmartCore::Schema::TypeSystem::SmartTypes::Operation
4
+ # @api private
5
+ # @since 0.12.0
6
+ class Cast < Base
7
+ # @param value [Any]
8
+ # @return [Any]
9
+ #
10
+ # @api private
11
+ # @since 0.12.0
12
+ def call(value)
13
+ type.cast(value)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SmartCore::Schema::TypeSystem::SmartTypes::Operation
4
+ # @api private
5
+ # @since 0.12.0
6
+ class Valid < Base
7
+ # @param value [Any]
8
+ # @return [Boolean]
9
+ #
10
+ # @api private
11
+ # @since 0.12.0
12
+ def call(value)
13
+ type.valid?(value)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SmartCore::Schema::TypeSystem::SmartTypes::Operation
4
+ # @api private
5
+ # @since 0.12.0
6
+ class Validate < Base
7
+ # @param value [Any]
8
+ # @return [void]
9
+ #
10
+ # @api private
11
+ # @since 0.12.0
12
+ def call(value)
13
+ type.validate!(value)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SmartCore::Schema::TypeSystem
4
+ # @abstract
5
+ # @api private
6
+ # @since 0.12.0
7
+ module SmartTypes::Operation
8
+ require_relative 'operation/base'
9
+ require_relative 'operation/valid'
10
+ require_relative 'operation/validate'
11
+ require_relative 'operation/cast'
12
+ end
13
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 0.12.0
5
+ class SmartCore::Schema::TypeSystem::SmartTypes < SmartCore::Schema::TypeSystem::Interop
6
+ require_relative 'smart_types/abstract_factory'
7
+ require_relative 'smart_types/operation'
8
+
9
+ type_alias('value.any', SmartCore::Types::Value::Any)
10
+ type_alias('value.nil', SmartCore::Types::Value::Nil)
11
+ type_alias('value.string', SmartCore::Types::Value::String)
12
+ type_alias('value.symbol', SmartCore::Types::Value::Symbol)
13
+ type_alias('value.text', SmartCore::Types::Value::Text)
14
+ type_alias('value.integer', SmartCore::Types::Value::Integer)
15
+ type_alias('value.float', SmartCore::Types::Value::Float)
16
+ type_alias('value.numeric', SmartCore::Types::Value::Numeric)
17
+ type_alias('value.big_decimal', SmartCore::Types::Value::BigDecimal)
18
+ type_alias('value.boolean', SmartCore::Types::Value::Boolean)
19
+ type_alias('value.array', SmartCore::Types::Value::Array)
20
+ type_alias('value.hash', SmartCore::Types::Value::Hash)
21
+ type_alias('value.proc', SmartCore::Types::Value::Proc)
22
+ type_alias('value.class', SmartCore::Types::Value::Class)
23
+ type_alias('value.module', SmartCore::Types::Value::Module)
24
+ type_alias('value.time', SmartCore::Types::Value::Time)
25
+ type_alias('value.date_time', SmartCore::Types::Value::DateTime)
26
+ type_alias('value.date', SmartCore::Types::Value::Date)
27
+ type_alias('value.time_based', SmartCore::Types::Value::TimeBased)
28
+
29
+ type_alias(:any, SmartCore::Types::Value::Any)
30
+ type_alias(:nil, SmartCore::Types::Value::Nil)
31
+ type_alias(:string, SmartCore::Types::Value::String)
32
+ type_alias(:symbol, SmartCore::Types::Value::Symbol)
33
+ type_alias(:text, SmartCore::Types::Value::Text)
34
+ type_alias(:integer, SmartCore::Types::Value::Integer)
35
+ type_alias(:float, SmartCore::Types::Value::Float)
36
+ type_alias(:numeric, SmartCore::Types::Value::Numeric)
37
+ type_alias(:big_decimal, SmartCore::Types::Value::BigDecimal)
38
+ type_alias(:boolean, SmartCore::Types::Value::Boolean)
39
+ type_alias(:array, SmartCore::Types::Value::Array)
40
+ type_alias(:hash, SmartCore::Types::Value::Hash)
41
+ type_alias(:proc, SmartCore::Types::Value::Proc)
42
+ type_alias(:class, SmartCore::Types::Value::Class)
43
+ type_alias(:module, SmartCore::Types::Value::Module)
44
+ type_alias(:time, SmartCore::Types::Value::Time)
45
+ type_alias(:date_time, SmartCore::Types::Value::DateTime)
46
+ type_alias(:date, SmartCore::Types::Value::Date)
47
+ type_alias(:time_based, SmartCore::Types::Value::TimeBased)
48
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api pulic
4
+ # @since 0.12.0
5
+ module SmartCore::Schema::TypeSystem
6
+ require_relative 'type_system/interop'
7
+ require_relative 'type_system/registry'
8
+ require_relative 'type_system/smart_types'
9
+ require_relative 'type_system/registry_interface'
10
+
11
+ # @since 0.12.0
12
+ extend SmartCore::Schema::TypeSystem::RegistryInterface
13
+
14
+ # @since 0.12.0
15
+ register(:smart_types, SmartCore::Schema::TypeSystem::SmartTypes)
16
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SmartCore
4
+ # rubocop:disable Style/StaticClass
5
+ class Schema
6
+ # @return [String]
7
+ #
8
+ # @api public
9
+ # @since 0.1.0
10
+ # @version 0.12.2
11
+ VERSION = '0.12.2'
12
+ end
13
+ # rubocop:enable Style/StaticClass
14
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'smart_core'
4
+ require 'smart_core/types'
5
+ require 'forwardable'
6
+
7
+ # @api pulic
8
+ # @since 0.1.0
9
+ module SmartCore
10
+ # @api public
11
+ # @since 0.1.0
12
+ class Schema
13
+ require_relative 'schema/version'
14
+ require_relative 'schema/errors'
15
+ require_relative 'schema/plugins'
16
+ require_relative 'schema/type_system'
17
+ require_relative 'schema/configuration'
18
+ require_relative 'schema/key_control'
19
+ require_relative 'schema/result'
20
+ require_relative 'schema/checker'
21
+ require_relative 'schema/dsl'
22
+
23
+ # @since 0.1.0
24
+ include SmartCore::Schema::DSL
25
+
26
+ # @sicnce 0.12.0
27
+ extend SmartCore::Schema::Plugins::AccessMixin
28
+
29
+ class << self
30
+ # NOTE/TODO: will be totally reworked with dynamic schema-instance-configurated type-system
31
+ #
32
+ # @api public
33
+ # @since 0.12.0
34
+ def type_system
35
+ SmartCore::Schema::TypeSystem.resolve(SmartCore::Schema::Configuration[:type_system])
36
+ end
37
+ end
38
+
39
+ # @param verifiable_hash [Hash<String|Symbol,Any>]
40
+ # @return [Boolean]
41
+ #
42
+ # @api public
43
+ # @since 0.1.0
44
+ def valid?(verifiable_hash)
45
+ validate(verifiable_hash).success?
46
+ end
47
+
48
+ # @param verifiable_hash [Hash<String|Symbol,Any>]
49
+ # @return [SmartCore::Schema::Result]
50
+ #
51
+ # @api public
52
+ # @since 0.1.0
53
+ def validate(verifiable_hash)
54
+ schema_checker.check!(verifiable_hash)
55
+ end
56
+
57
+ private
58
+
59
+ # @return [SmartCore::Schema::Checker]
60
+ #
61
+ # @api private
62
+ # @since 0.1.0
63
+ def schema_checker
64
+ self.class.__schema_checker__
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/smart_core/schema/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.required_ruby_version = Gem::Requirement.new('>= 3.3')
7
+
8
+ spec.name = 'smart_schema'
9
+ spec.version = SmartCore::Schema::VERSION
10
+ spec.authors = ['Rustam Ibragimov']
11
+ spec.email = ['iamdaiver@gmail.com']
12
+
13
+ spec.summary = 'SmartCore::Schema is a schema validator for Hash-like data structures'
14
+ spec.description = 'SmartCore::Schema is a schema validator for Hash-like data structures'
15
+ spec.homepage = 'https://github.com/smart-rb/smart_schema'
16
+ spec.license = 'MIT'
17
+
18
+ spec.metadata['homepage_uri'] =
19
+ spec.homepage
20
+ spec.metadata['source_code_uri'] =
21
+ 'https://github.com/smart-rb/smart_schema'
22
+ spec.metadata['changelog_uri'] =
23
+ 'https://github.com/smart-rb/smart_schema/blob/master/CHANGELOG.md'
24
+
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+
33
+ spec.add_dependency 'smart_engine', '~> 0.17'
34
+ spec.add_dependency 'smart_types', '~> 0.8'
35
+ spec.add_dependency 'qonfig', '~> 0.30'
36
+
37
+ spec.add_development_dependency 'dry-types', '~> 1.9'
38
+
39
+ spec.add_development_dependency 'pry', '~> 0.16'
40
+ spec.add_development_dependency 'pry-doc', '~> 1.7'
41
+ spec.add_development_dependency 'bundler' # rubocop:disable Gemspec/DependencyVersion
42
+ spec.add_development_dependency 'rake', '~> 13.3'
43
+ spec.add_development_dependency 'rspec', '~> 3.13'
44
+ spec.add_development_dependency 'armitage-rubocop', '~> 1.81'
45
+ spec.add_development_dependency 'simplecov', '~> 0.22'
46
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.1
4
+ version: 0.12.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rustam Ibragimov
@@ -169,7 +169,87 @@ email:
169
169
  executables: []
170
170
  extensions: []
171
171
  extra_rdoc_files: []
172
- files: []
172
+ files:
173
+ - ".gitignore"
174
+ - ".rspec"
175
+ - ".rubocop.yml"
176
+ - CHANGELOG.md
177
+ - CODE_OF_CONDUCT.md
178
+ - Gemfile
179
+ - Gemfile.lock
180
+ - LICENSE.txt
181
+ - README.md
182
+ - Rakefile
183
+ - bin/console
184
+ - bin/setup
185
+ - lib/smart_core/schema.rb
186
+ - lib/smart_core/schema/checker.rb
187
+ - lib/smart_core/schema/checker/reconciler.rb
188
+ - lib/smart_core/schema/checker/reconciler/constructor.rb
189
+ - lib/smart_core/schema/checker/reconciler/matcher.rb
190
+ - lib/smart_core/schema/checker/reconciler/matcher/options.rb
191
+ - lib/smart_core/schema/checker/reconciler/matcher/result.rb
192
+ - lib/smart_core/schema/checker/reconciler/matcher/result_finalizer.rb
193
+ - lib/smart_core/schema/checker/rules.rb
194
+ - lib/smart_core/schema/checker/rules/base.rb
195
+ - lib/smart_core/schema/checker/rules/extra_keys.rb
196
+ - lib/smart_core/schema/checker/rules/extra_keys/failure.rb
197
+ - lib/smart_core/schema/checker/rules/extra_keys/result.rb
198
+ - lib/smart_core/schema/checker/rules/extra_keys/success.rb
199
+ - lib/smart_core/schema/checker/rules/optional.rb
200
+ - lib/smart_core/schema/checker/rules/options.rb
201
+ - lib/smart_core/schema/checker/rules/options/empty.rb
202
+ - lib/smart_core/schema/checker/rules/options/filled.rb
203
+ - lib/smart_core/schema/checker/rules/options/type.rb
204
+ - lib/smart_core/schema/checker/rules/required.rb
205
+ - lib/smart_core/schema/checker/rules/requirement.rb
206
+ - lib/smart_core/schema/checker/rules/requirement/optional.rb
207
+ - lib/smart_core/schema/checker/rules/requirement/required.rb
208
+ - lib/smart_core/schema/checker/rules/requirement/result.rb
209
+ - lib/smart_core/schema/checker/rules/result.rb
210
+ - lib/smart_core/schema/checker/rules/result/base.rb
211
+ - lib/smart_core/schema/checker/rules/result/failure.rb
212
+ - lib/smart_core/schema/checker/rules/result/success.rb
213
+ - lib/smart_core/schema/checker/rules/type_aliases.rb
214
+ - lib/smart_core/schema/checker/rules/verifier.rb
215
+ - lib/smart_core/schema/checker/rules/verifier/result.rb
216
+ - lib/smart_core/schema/checker/verifiable_hash.rb
217
+ - lib/smart_core/schema/configuration.rb
218
+ - lib/smart_core/schema/dsl.rb
219
+ - lib/smart_core/schema/errors.rb
220
+ - lib/smart_core/schema/key_control.rb
221
+ - lib/smart_core/schema/plugins.rb
222
+ - lib/smart_core/schema/plugins/abstract.rb
223
+ - lib/smart_core/schema/plugins/access_mixin.rb
224
+ - lib/smart_core/schema/plugins/dry_types.rb
225
+ - lib/smart_core/schema/plugins/dry_types/dry_types.rb
226
+ - lib/smart_core/schema/plugins/dry_types/dry_types/abstract_factory.rb
227
+ - lib/smart_core/schema/plugins/dry_types/dry_types/operation.rb
228
+ - lib/smart_core/schema/plugins/dry_types/dry_types/operation/base.rb
229
+ - lib/smart_core/schema/plugins/dry_types/dry_types/operation/cast.rb
230
+ - lib/smart_core/schema/plugins/dry_types/dry_types/operation/valid.rb
231
+ - lib/smart_core/schema/plugins/dry_types/dry_types/operation/validate.rb
232
+ - lib/smart_core/schema/plugins/dry_types/errors.rb
233
+ - lib/smart_core/schema/plugins/registry.rb
234
+ - lib/smart_core/schema/plugins/registry_interface.rb
235
+ - lib/smart_core/schema/result.rb
236
+ - lib/smart_core/schema/type_system.rb
237
+ - lib/smart_core/schema/type_system/interop.rb
238
+ - lib/smart_core/schema/type_system/interop/abstract_factory.rb
239
+ - lib/smart_core/schema/type_system/interop/aliasing.rb
240
+ - lib/smart_core/schema/type_system/interop/aliasing/alias_list.rb
241
+ - lib/smart_core/schema/type_system/interop/operation.rb
242
+ - lib/smart_core/schema/type_system/registry.rb
243
+ - lib/smart_core/schema/type_system/registry_interface.rb
244
+ - lib/smart_core/schema/type_system/smart_types.rb
245
+ - lib/smart_core/schema/type_system/smart_types/abstract_factory.rb
246
+ - lib/smart_core/schema/type_system/smart_types/operation.rb
247
+ - lib/smart_core/schema/type_system/smart_types/operation/base.rb
248
+ - lib/smart_core/schema/type_system/smart_types/operation/cast.rb
249
+ - lib/smart_core/schema/type_system/smart_types/operation/valid.rb
250
+ - lib/smart_core/schema/type_system/smart_types/operation/validate.rb
251
+ - lib/smart_core/schema/version.rb
252
+ - smart_schema.gemspec
173
253
  homepage: https://github.com/smart-rb/smart_schema
174
254
  licenses:
175
255
  - MIT
@@ -191,7 +271,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
271
  - !ruby/object:Gem::Version
192
272
  version: '0'
193
273
  requirements: []
194
- rubygems_version: 3.6.9
274
+ rubygems_version: 4.0.3
195
275
  specification_version: 4
196
276
  summary: SmartCore::Schema is a schema validator for Hash-like data structures
197
277
  test_files: []