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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23e9302b311123a5b0837d868887c752af34a976
4
- data.tar.gz: 275eb8ded8c32e65f1daa4daab04c559937f1b58
3
+ metadata.gz: 689c8c7026e418ee31898770feab157880a985eb
4
+ data.tar.gz: ec2ea8c9c77caf975a1a14e041cafaeab2cb81f9
5
5
  SHA512:
6
- metadata.gz: 30f2f5ca6da4eed2d5d94a1e967f260e561343db487d14b0114b2f77e40da3d71b4f3c7356520390678746f49fe459f45b7c01f70ddf4f29ab6506ec267d654e
7
- data.tar.gz: aecc915fd810136e9465f9921f8878005b3ebc6edb1d4d0f101f1cfc5103b85fa8c79139f6bec9dba6aa0c1dc182bc10d879a5c807cce72356d12c1f3e2a5e6a
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 implicit keys #{v.keys} != #{object.keys.sort}" unless v.keys.sort == object.keys.sort
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.2"
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.2
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-14 00:00:00.000000000 Z
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.