nakischema 0.0.2 → 0.0.3
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 +5 -3
- data/nakischema.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 689c8c7026e418ee31898770feab157880a985eb
|
4
|
+
data.tar.gz: ec2ea8c9c77caf975a1a14e041cafaeab2cb81f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4dd0ad379925c22804b8d261cf829051b3333123b682bba08b4100fcb7fb6aec81473b12b4611d0d35ce89abfdd645f19affa3f6f1a746cf1e377ebee0ef6bc
|
7
|
+
data.tar.gz: 40dc899497e377794e6af4fb5c1583de143a32c384bdb4595a94af8a671b2c6ba377a821f019da9737f26bfd8ffe998824c23c92c0fae0263a262ad7d48c91b7
|
data/lib/nakischema.rb
CHANGED
@@ -11,15 +11,17 @@ module Nakischema
|
|
11
11
|
raise_with_path.call "expected Array != #{object.class}" unless object.is_a? Array unless (schema.keys & %i{ size }).empty?
|
12
12
|
schema.each do |k, v|
|
13
13
|
case k
|
14
|
-
# when :keys_sorted ; raise_with_path.call "expected explicit keys #{v} != #{object.keys.sort}" unless v == object.keys.sort
|
15
14
|
when :size ; raise_with_path.call "expected explicit size #{v} != #{object.size}" unless v.include? object.size
|
16
15
|
# when Fixnum
|
17
16
|
# raise_with_path.call "expected Array != #{object.class}" unless object.is_a? Array
|
18
17
|
# validate object[k], v, [*path, :"##{k}"]
|
19
18
|
when :keys ; validate object.keys, v, [*path, :keys]
|
19
|
+
when :values ; validate object.values, v, [*path, :values]
|
20
|
+
when :keys_sorted ; validate object.keys.sort, v, [*path, :keys_sorted]
|
20
21
|
when :hash_opt ; v.each{ |k, v| validate object.fetch(k), v, [*path, k] if object.key? k }
|
21
22
|
when :hash_req ; v.each{ |k, v| validate object.fetch(k), v, [*path, k] }
|
22
|
-
when :hash ; raise_with_path.call "expected
|
23
|
+
when :hash ; raise_with_path.call "expected Hash != #{object.class}" unless object.is_a? Hash
|
24
|
+
raise_with_path.call "expected implicit keys #{v.keys} != #{object.keys.sort}" unless v.keys.sort == object.keys.sort
|
23
25
|
v.each{ |k, v| validate object.fetch(k), v, [*path, k] }
|
24
26
|
when :each_key ; object.keys.each_with_index{ |k, i| validate k, v, [*path, :"key##{i}"] }
|
25
27
|
when :each_value ; object.values.each_with_index{ |v_, i| validate v_, v, [*path, :"value##{i}"] }
|
@@ -55,7 +57,7 @@ module Nakischema
|
|
55
57
|
when Array
|
56
58
|
if schema.map(&:class) == [Array]
|
57
59
|
raise_with_path.call "expected Array != #{object.class}" unless object.is_a? Array
|
58
|
-
raise_with_path.call "expected implicit size #{schema[0].size} != #{object.size}" unless schema[0].size == object.size
|
60
|
+
raise_with_path.call "expected implicit size #{schema[0].size} != #{object.size} for #{object.inspect}" unless schema[0].size == object.size
|
59
61
|
object.zip(schema[0]).each_with_index{ |(o, v), i| validate o, v, [*path, :"##{i}"] }
|
60
62
|
else
|
61
63
|
results = schema.lazy.with_index.map do |v, i|
|
data/nakischema.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "nakischema"
|
3
|
-
spec.version = "0.0.
|
3
|
+
spec.version = "0.0.3"
|
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.0.
|
4
|
+
version: 0.0.3
|
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: 2021-08-
|
11
|
+
date: 2021-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: The most compact yet powerful arbitrary nested objects validator. Especially
|
14
14
|
handy to validate JSONs.
|