nakischema 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nakischema.rb +23 -12
- data/nakischema.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63a4f15494ac50f198c795a569e50304326cbb309e5a30bd0b0446c702da5212
|
4
|
+
data.tar.gz: a20e6a51a422b271b1bb98d5f4be387bd3aa89fa8dc1ac5e8701b3376bd6ba82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e702f55dffb989ae23ab8c0b9b4d0ad2fc2fdf7f1da3e1b90528b3c370c7bd39409fc49d844e65b2d13a1174c153c8f8dab1d17950c3981757d5f680477b7b8
|
7
|
+
data.tar.gz: 5ae028759edb1366dce9203a6cc68c15e23875efaa2ac47dcb3432fc1324ad08badb2d21772fe069735f64d3127063b4703598f41abfc163d6207a509f6636de
|
data/lib/nakischema.rb
CHANGED
@@ -7,7 +7,7 @@ module Nakischema
|
|
7
7
|
end
|
8
8
|
# TODO: maybe move '(at ...)' to the beginning
|
9
9
|
case schema
|
10
|
-
when NilClass, TrueClass, FalseClass, String, Symbol ; raise_with_path.call "expected #{schema.inspect} != #{object.inspect}" unless schema
|
10
|
+
when NilClass, TrueClass, FalseClass, String, Symbol ; raise_with_path.call "expected #{schema.inspect} != #{object.inspect}" unless schema === object
|
11
11
|
# TODO: maybe deprecate the NilClass, TrueClass, FalseClass since they can be asserted via the next case branch
|
12
12
|
when Class ; raise_with_path.call "expected #{schema } != #{object.class }" unless schema === object
|
13
13
|
when Regexp ; raise_with_path.call "expected #{schema } != #{object.inspect}" unless schema === object
|
@@ -86,6 +86,13 @@ module Nakischema
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
+
def self.valid? object, schema
|
90
|
+
validate object, schema
|
91
|
+
true
|
92
|
+
rescue Error
|
93
|
+
false
|
94
|
+
end
|
95
|
+
|
89
96
|
def self.validate_oga_xml object, schema, path = []
|
90
97
|
raise_with_path = lambda do |msg, _path = path|
|
91
98
|
raise Error.new "#{msg}#{" (at #{_path})" unless _path.empty?}"
|
@@ -141,28 +148,32 @@ module Nakischema
|
|
141
148
|
end
|
142
149
|
end
|
143
150
|
|
144
|
-
def self.fixture _
|
151
|
+
def self.fixture _, no_shuffle = false
|
145
152
|
require "regexp-examples"
|
146
153
|
require "addressable"
|
147
154
|
case _
|
155
|
+
when NilClass ; nil
|
148
156
|
when Hash
|
149
157
|
case _.keys
|
150
|
-
when %i{ hash } ; _[:hash ].map{ |k,v| [k,fixture(v)] }.shuffle.to_h
|
151
|
-
when %i{ hash_req } ; [*_[:hash_req].map{ |k,v| [k,fixture(v)] }, ["foo","bar"]].shuffle.to_h # TODO: assert no collision
|
152
|
-
when %i{ size each } ; Array.new(
|
158
|
+
when %i{ hash } ; _[:hash ].map{ |k,v| [k,fixture(v,no_shuffle)] } .then{ |_| no_shuffle ? _ : _.shuffle }.to_h
|
159
|
+
when %i{ hash_req } ; [*_[:hash_req].map{ |k,v| [k,fixture(v,no_shuffle)] }, ["foo","bar"]].then{ |_| no_shuffle ? _ : _.shuffle }.to_h # TODO: assert no collision
|
160
|
+
when %i{ size each } ; Array.new(_[:size].max){ fixture _[:each], no_shuffle }
|
153
161
|
else ; fail _.keys.inspect
|
154
162
|
end
|
155
|
-
when Array ; [Array] == _.map(&:class) ? _[0].map
|
163
|
+
when Array ; [Array] == _.map(&:class) ? _[0].map{ |_| fixture _, no_shuffle } : fixture(_.sample, no_shuffle)
|
156
164
|
when Regexp
|
157
|
-
|
158
|
-
|
159
|
-
URI t
|
165
|
+
begin
|
166
|
+
URI(t = _.random_example)
|
160
167
|
rescue URI::InvalidURIError
|
161
|
-
|
162
|
-
|
163
|
-
|
168
|
+
begin
|
169
|
+
URI Addressable::URI.escape t
|
170
|
+
rescue Addressable::URI::InvalidURIError
|
171
|
+
t
|
172
|
+
end
|
173
|
+
end.to_s
|
164
174
|
when Range ; rand _
|
165
175
|
when String ; _
|
176
|
+
when TrueClass ; true
|
166
177
|
when Class
|
167
178
|
case _.name
|
168
179
|
when "Integer" ; -rand(1000000)
|
data/nakischema.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "nakischema"
|
3
|
-
spec.version = "0.
|
3
|
+
spec.version = "0.3.0"
|
4
4
|
spec.summary = "compact yet powerful arbitrary nested objects validator"
|
5
5
|
spec.description = "The most compact yet powerful arbitrary nested objects validator. Especially handy to validate JSONs."
|
6
6
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nakischema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Maslov aka Nakilon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: regexp-examples
|