smart_schema 0.11.0 → 0.12.1
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.
- checksums.yaml +4 -4
- metadata +60 -71
- data/.gitignore +0 -12
- data/.rspec +0 -3
- data/.rubocop.yml +0 -20
- data/CHANGELOG.md +0 -68
- data/CODE_OF_CONDUCT.md +0 -74
- data/Gemfile +0 -5
- data/Gemfile.lock +0 -106
- data/LICENSE.txt +0 -21
- data/README.md +0 -236
- data/Rakefile +0 -21
- data/bin/console +0 -8
- data/bin/setup +0 -8
- data/lib/smart_core/schema/checker/reconciler/constructor.rb +0 -60
- data/lib/smart_core/schema/checker/reconciler/matcher/options.rb +0 -33
- data/lib/smart_core/schema/checker/reconciler/matcher/result.rb +0 -87
- data/lib/smart_core/schema/checker/reconciler/matcher/result_finalizer.rb +0 -186
- data/lib/smart_core/schema/checker/reconciler/matcher.rb +0 -62
- data/lib/smart_core/schema/checker/reconciler.rb +0 -106
- data/lib/smart_core/schema/checker/rules/base.rb +0 -110
- data/lib/smart_core/schema/checker/rules/extra_keys/failure.rb +0 -24
- data/lib/smart_core/schema/checker/rules/extra_keys/result.rb +0 -37
- data/lib/smart_core/schema/checker/rules/extra_keys/success.rb +0 -30
- data/lib/smart_core/schema/checker/rules/extra_keys.rb +0 -31
- data/lib/smart_core/schema/checker/rules/optional.rb +0 -25
- data/lib/smart_core/schema/checker/rules/options/empty.rb +0 -43
- data/lib/smart_core/schema/checker/rules/options/filled.rb +0 -49
- data/lib/smart_core/schema/checker/rules/options/type.rb +0 -86
- data/lib/smart_core/schema/checker/rules/options.rb +0 -60
- data/lib/smart_core/schema/checker/rules/required.rb +0 -25
- data/lib/smart_core/schema/checker/rules/requirement/optional.rb +0 -36
- data/lib/smart_core/schema/checker/rules/requirement/required.rb +0 -36
- data/lib/smart_core/schema/checker/rules/requirement/result.rb +0 -95
- data/lib/smart_core/schema/checker/rules/requirement.rb +0 -9
- data/lib/smart_core/schema/checker/rules/result/base.rb +0 -44
- data/lib/smart_core/schema/checker/rules/result/failure.rb +0 -41
- data/lib/smart_core/schema/checker/rules/result/success.rb +0 -15
- data/lib/smart_core/schema/checker/rules/result.rb +0 -9
- data/lib/smart_core/schema/checker/rules/type_aliases.rb +0 -57
- data/lib/smart_core/schema/checker/rules/verifier/result.rb +0 -75
- data/lib/smart_core/schema/checker/rules/verifier.rb +0 -74
- data/lib/smart_core/schema/checker/rules.rb +0 -89
- data/lib/smart_core/schema/checker/verifiable_hash.rb +0 -65
- data/lib/smart_core/schema/checker.rb +0 -106
- data/lib/smart_core/schema/dsl.rb +0 -81
- data/lib/smart_core/schema/errors.rb +0 -13
- data/lib/smart_core/schema/key_control.rb +0 -39
- data/lib/smart_core/schema/result.rb +0 -62
- data/lib/smart_core/schema/version.rb +0 -14
- data/lib/smart_core/schema.rb +0 -52
- data/smart_schema.gemspec +0 -42
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# @api private
|
|
4
|
-
# @since 0.1.0
|
|
5
|
-
module SmartCore::Schema::DSL
|
|
6
|
-
class << self
|
|
7
|
-
# @param base_klass [Class]
|
|
8
|
-
# @return [void]
|
|
9
|
-
#
|
|
10
|
-
# @api private
|
|
11
|
-
# @since 0.1.0
|
|
12
|
-
def included(base_klass)
|
|
13
|
-
base_klass.instance_variable_set(:@__schema_checker__, SmartCore::Schema::Checker.new)
|
|
14
|
-
base_klass.extend(ClassMethods)
|
|
15
|
-
base_klass.singleton_class.prepend(ClassInheritance)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
# @api private
|
|
20
|
-
# @since 0.1.0
|
|
21
|
-
module ClassInheritance
|
|
22
|
-
# @param child_klass [Class]
|
|
23
|
-
# @return [void]
|
|
24
|
-
#
|
|
25
|
-
# @api private
|
|
26
|
-
# @since 0.1.0
|
|
27
|
-
def inherited(child_klass)
|
|
28
|
-
child_klass.instance_variable_set(
|
|
29
|
-
:@__schema_checker__,
|
|
30
|
-
SmartCore::Schema::Checker.new.combine_with(__schema_checker__)
|
|
31
|
-
)
|
|
32
|
-
child_klass.singleton_class.prepend(ClassInheritance)
|
|
33
|
-
super
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
# @api private
|
|
38
|
-
# @since 0.1.0
|
|
39
|
-
# @version 0.3.0
|
|
40
|
-
module ClassMethods
|
|
41
|
-
# @return [SmartCore::Schema::Checker]
|
|
42
|
-
#
|
|
43
|
-
# @api private
|
|
44
|
-
# @since 0.1.0
|
|
45
|
-
def __schema_checker__
|
|
46
|
-
@__schema_checker__
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
# @param strict_mode [NilClass, String, Symbol]
|
|
50
|
-
# @param definitions [Block]
|
|
51
|
-
# @return [void]
|
|
52
|
-
#
|
|
53
|
-
# @note nil strict mode means `do not change current mode`
|
|
54
|
-
#
|
|
55
|
-
# @api public
|
|
56
|
-
# @since 0.1.0
|
|
57
|
-
# @version 0.3.0
|
|
58
|
-
def schema(strict_mode = nil, &definitions)
|
|
59
|
-
__schema_checker__.invoke_in_pipe do
|
|
60
|
-
set_strict_mode(strict_mode)
|
|
61
|
-
append_schema_definitions(&definitions)
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
# @return [void]
|
|
66
|
-
#
|
|
67
|
-
# @api public
|
|
68
|
-
# @since 0.3.0
|
|
69
|
-
def strict!
|
|
70
|
-
__schema_checker__.set_strict_mode(:strict)
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
# @return [void]
|
|
74
|
-
#
|
|
75
|
-
# @api public
|
|
76
|
-
# @since 0.3.0
|
|
77
|
-
def non_strict!
|
|
78
|
-
__schema_checker__.set_strict_mode(:non_strict)
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
end
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# rubocop:disable Style/StaticClass
|
|
4
|
-
class SmartCore::Schema
|
|
5
|
-
# @api public
|
|
6
|
-
# @since 0.1.0
|
|
7
|
-
Error = Class.new(SmartCore::Error)
|
|
8
|
-
|
|
9
|
-
# @api public
|
|
10
|
-
# @since 0.1.0
|
|
11
|
-
ArgumentError = Class.new(SmartCore::ArgumentError)
|
|
12
|
-
end
|
|
13
|
-
# rubocop:enable Style/StaticClass
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# @api private
|
|
4
|
-
# @since 0.1.0
|
|
5
|
-
module SmartCore::Schema::KeyControl
|
|
6
|
-
class << self
|
|
7
|
-
# @param key [String, Symbol]
|
|
8
|
-
# @return [String]
|
|
9
|
-
#
|
|
10
|
-
# @api private
|
|
11
|
-
# @since 0.1.0
|
|
12
|
-
def normalize(key)
|
|
13
|
-
prevent_incompatible!(key)
|
|
14
|
-
key.to_s
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# @param keys [Array<String,Symbol>]
|
|
18
|
-
# @return [Array<String>]
|
|
19
|
-
#
|
|
20
|
-
# @api private
|
|
21
|
-
# @since 0.1.0
|
|
22
|
-
def normalize_list(keys)
|
|
23
|
-
keys.map { |key| normalize(key) }
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
# @param key [String, Symbol]
|
|
27
|
-
# @return [void]
|
|
28
|
-
#
|
|
29
|
-
# @api private
|
|
30
|
-
# @since 0.1.0
|
|
31
|
-
def prevent_incompatible!(key)
|
|
32
|
-
unless key.is_a?(String) || key.is_a?(Symbol)
|
|
33
|
-
raise(SmartCore::Schema::ArgumentError, <<~ERROR_MESSAGE)
|
|
34
|
-
Schema keys should be a type of string or symbol
|
|
35
|
-
ERROR_MESSAGE
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# @api private
|
|
4
|
-
# @since 0.1.0
|
|
5
|
-
# @version 0.3.0
|
|
6
|
-
class SmartCore::Schema::Result
|
|
7
|
-
# @return [Hash<String,Any>]
|
|
8
|
-
#
|
|
9
|
-
# @api public
|
|
10
|
-
# @since 0.1.0
|
|
11
|
-
attr_reader :source
|
|
12
|
-
|
|
13
|
-
# @return [Hash<String,Array<Symbol>>]
|
|
14
|
-
#
|
|
15
|
-
# @api public
|
|
16
|
-
# @since 0.1.0
|
|
17
|
-
attr_reader :errors
|
|
18
|
-
|
|
19
|
-
# @return [Set<String>]
|
|
20
|
-
#
|
|
21
|
-
# @api public
|
|
22
|
-
# @since 0.1.0
|
|
23
|
-
attr_reader :extra_keys
|
|
24
|
-
|
|
25
|
-
# @return [Set<String>]
|
|
26
|
-
#
|
|
27
|
-
# @api public
|
|
28
|
-
# @since 0.3.0
|
|
29
|
-
attr_reader :spread_keys
|
|
30
|
-
|
|
31
|
-
# @param source [Hash<String|Symbol,Any>]
|
|
32
|
-
# @param errors [Hash<String,Array<Symbol>]
|
|
33
|
-
# @param extra_keys [Set<String>]
|
|
34
|
-
# @param spread_keys [Set<String>]
|
|
35
|
-
# @return [void]
|
|
36
|
-
#
|
|
37
|
-
# @api private
|
|
38
|
-
# @since 0.1.0
|
|
39
|
-
# @version 0.3.0
|
|
40
|
-
def initialize(source, errors, extra_keys, spread_keys)
|
|
41
|
-
@source = source
|
|
42
|
-
@errors = errors
|
|
43
|
-
@extra_keys = extra_keys
|
|
44
|
-
@spread_keys = spread_keys
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
# @return [Boolean]
|
|
48
|
-
#
|
|
49
|
-
# @api public
|
|
50
|
-
# @since 0.1.0
|
|
51
|
-
def success?
|
|
52
|
-
errors.empty? && extra_keys.empty?
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
# @return [Boolean]
|
|
56
|
-
#
|
|
57
|
-
# @api public
|
|
58
|
-
# @since 0.1.0
|
|
59
|
-
def failure?
|
|
60
|
-
errors.any? || extra_keys.any?
|
|
61
|
-
end
|
|
62
|
-
end
|
|
@@ -1,14 +0,0 @@
|
|
|
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.11.0
|
|
11
|
-
VERSION = '0.11.0'
|
|
12
|
-
end
|
|
13
|
-
# rubocop:enable Style/StaticClass
|
|
14
|
-
end
|
data/lib/smart_core/schema.rb
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'smart_core'
|
|
4
|
-
require 'smart_core/types'
|
|
5
|
-
require 'set'
|
|
6
|
-
require 'forwardable'
|
|
7
|
-
|
|
8
|
-
# @api pulic
|
|
9
|
-
# @since 0.1.0
|
|
10
|
-
module SmartCore
|
|
11
|
-
# @api public
|
|
12
|
-
# @since 0.1.0
|
|
13
|
-
class Schema
|
|
14
|
-
require_relative 'schema/version'
|
|
15
|
-
require_relative 'schema/errors'
|
|
16
|
-
require_relative 'schema/key_control'
|
|
17
|
-
require_relative 'schema/result'
|
|
18
|
-
require_relative 'schema/checker'
|
|
19
|
-
require_relative 'schema/dsl'
|
|
20
|
-
|
|
21
|
-
# @since 0.1.0
|
|
22
|
-
include SmartCore::Schema::DSL
|
|
23
|
-
|
|
24
|
-
# @param verifiable_hash [Hash<String|Symbol,Any>]
|
|
25
|
-
# @return [Boolean]
|
|
26
|
-
#
|
|
27
|
-
# @api public
|
|
28
|
-
# @since 0.1.0
|
|
29
|
-
def valid?(verifiable_hash)
|
|
30
|
-
validate(verifiable_hash).success?
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
# @param verifiable_hash [Hash<String|Symbol,Any>]
|
|
34
|
-
# @return [SmartCore::Schema::Result]
|
|
35
|
-
#
|
|
36
|
-
# @api public
|
|
37
|
-
# @since 0.1.0
|
|
38
|
-
def validate(verifiable_hash)
|
|
39
|
-
schema_checker.check!(verifiable_hash)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
private
|
|
43
|
-
|
|
44
|
-
# @return [SmartCore::Schema::Checker]
|
|
45
|
-
#
|
|
46
|
-
# @api private
|
|
47
|
-
# @since 0.1.0
|
|
48
|
-
def schema_checker
|
|
49
|
-
self.class.__schema_checker__
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
data/smart_schema.gemspec
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
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('>= 2.7')
|
|
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
|
-
|
|
36
|
-
spec.add_development_dependency 'pry', '~> 0.13'
|
|
37
|
-
spec.add_development_dependency 'bundler', '~> 2.2'
|
|
38
|
-
spec.add_development_dependency 'rake', '~> 13.0'
|
|
39
|
-
spec.add_development_dependency 'rspec', '~> 3.10'
|
|
40
|
-
spec.add_development_dependency 'armitage-rubocop', '~> 1.7'
|
|
41
|
-
spec.add_development_dependency 'simplecov', '~> 0.21'
|
|
42
|
-
end
|