json_schematize 0.8.0 → 0.9.0
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
- data/Gemfile.lock +27 -24
- data/lib/json_schematize/field.rb +11 -2
- data/lib/json_schematize/generator.rb +3 -1
- data/lib/json_schematize/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41661866a0f6debaa7bacc0897f12f00fe0ee156deb2c18dbacd28ef205a1079
|
4
|
+
data.tar.gz: d053b83bc1b4a3fb39b80ad18e126fa535102beeb988e036ab0d76564934af22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c8d4f0c708c44330f76d64b280b0dfdc2f8a3cf8aa8f99de36ad5ad4bdb0a9e41ba1329b128730942016195e456cd1842bae61d3782108462305a174244f7de
|
7
|
+
data.tar.gz: e64e2b257ea5c8cf8db6e1e01d88297a7f3a15724cb8efacb4bac4a2953aad4e2208e70f1f579e428181d5265170fbfa07f2a8bb736a08fe8193b66556627003
|
data/Gemfile.lock
CHANGED
@@ -1,59 +1,62 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
json_schematize (0.
|
4
|
+
json_schematize (0.9.0)
|
5
|
+
class_composer (~> 1.0)
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
8
9
|
specs:
|
9
|
-
activesupport (7.0.
|
10
|
+
activesupport (7.0.4.3)
|
10
11
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
11
12
|
i18n (>= 1.6, < 2)
|
12
13
|
minitest (>= 5.1)
|
13
14
|
tzinfo (~> 2.0)
|
14
15
|
byebug (11.1.3)
|
16
|
+
class_composer (1.0.2)
|
15
17
|
coderay (1.1.3)
|
16
|
-
concurrent-ruby (1.
|
18
|
+
concurrent-ruby (1.2.2)
|
17
19
|
diff-lcs (1.5.0)
|
18
20
|
docile (1.4.0)
|
19
|
-
faker (
|
21
|
+
faker (3.1.1)
|
20
22
|
i18n (>= 1.8.11, < 2)
|
21
|
-
i18n (1.
|
23
|
+
i18n (1.12.0)
|
22
24
|
concurrent-ruby (~> 1.0)
|
23
25
|
method_source (1.0.0)
|
24
|
-
minitest (5.
|
25
|
-
pry (0.
|
26
|
+
minitest (5.18.0)
|
27
|
+
pry (0.14.2)
|
26
28
|
coderay (~> 1.1)
|
27
29
|
method_source (~> 1.0)
|
28
|
-
pry-byebug (3.
|
30
|
+
pry-byebug (3.10.1)
|
29
31
|
byebug (~> 11.0)
|
30
|
-
pry (
|
32
|
+
pry (>= 0.13, < 0.15)
|
31
33
|
rake (12.3.3)
|
32
|
-
rspec (3.
|
33
|
-
rspec-core (~> 3.
|
34
|
-
rspec-expectations (~> 3.
|
35
|
-
rspec-mocks (~> 3.
|
36
|
-
rspec-core (3.
|
37
|
-
rspec-support (~> 3.
|
38
|
-
rspec-expectations (3.
|
34
|
+
rspec (3.12.0)
|
35
|
+
rspec-core (~> 3.12.0)
|
36
|
+
rspec-expectations (~> 3.12.0)
|
37
|
+
rspec-mocks (~> 3.12.0)
|
38
|
+
rspec-core (3.12.1)
|
39
|
+
rspec-support (~> 3.12.0)
|
40
|
+
rspec-expectations (3.12.2)
|
39
41
|
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
-
rspec-support (~> 3.
|
41
|
-
rspec-mocks (3.
|
42
|
+
rspec-support (~> 3.12.0)
|
43
|
+
rspec-mocks (3.12.5)
|
42
44
|
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
-
rspec-support (~> 3.
|
44
|
-
rspec-support (3.
|
45
|
-
rspec_junit_formatter (0.
|
45
|
+
rspec-support (~> 3.12.0)
|
46
|
+
rspec-support (3.12.0)
|
47
|
+
rspec_junit_formatter (0.6.0)
|
46
48
|
rspec-core (>= 2, < 4, != 2.12.0)
|
47
|
-
simplecov (0.
|
49
|
+
simplecov (0.22.0)
|
48
50
|
docile (~> 1.1)
|
49
51
|
simplecov-html (~> 0.11)
|
50
52
|
simplecov_json_formatter (~> 0.1)
|
51
53
|
simplecov-html (0.12.3)
|
52
54
|
simplecov_json_formatter (0.1.4)
|
53
|
-
tzinfo (2.0.
|
55
|
+
tzinfo (2.0.6)
|
54
56
|
concurrent-ruby (~> 1.0)
|
55
57
|
|
56
58
|
PLATFORMS
|
59
|
+
x86_64-darwin-20
|
57
60
|
x86_64-linux
|
58
61
|
|
59
62
|
DEPENDENCIES
|
@@ -68,4 +71,4 @@ DEPENDENCIES
|
|
68
71
|
simplecov
|
69
72
|
|
70
73
|
BUNDLED WITH
|
71
|
-
2.
|
74
|
+
2.4.8
|
@@ -39,7 +39,11 @@ class JsonSchematize::Field
|
|
39
39
|
|
40
40
|
def acceptable_value?(transformed_value:, raise_on_error:)
|
41
41
|
if array_of_types
|
42
|
-
|
42
|
+
if transformed_value.is_a?(empty_value) && required == false
|
43
|
+
boolean = true
|
44
|
+
else
|
45
|
+
boolean = transformed_value.all? { |val| validate_acceptable_types(val: val) }
|
46
|
+
end
|
43
47
|
else
|
44
48
|
boolean = validate_acceptable_types(val: transformed_value)
|
45
49
|
end
|
@@ -53,7 +57,11 @@ class JsonSchematize::Field
|
|
53
57
|
|
54
58
|
def acceptable_value_by_validator?(transformed_value:, raw_value:, raise_on_error:)
|
55
59
|
if array_of_types
|
56
|
-
|
60
|
+
if transformed_value.is_a?(empty_value) && required == false
|
61
|
+
boolean = true
|
62
|
+
else
|
63
|
+
boolean = transformed_value.all? { |val| validator.call(transformed_value, raw_value) }
|
64
|
+
end
|
57
65
|
else
|
58
66
|
boolean = validator.call(transformed_value, raw_value)
|
59
67
|
end
|
@@ -94,6 +102,7 @@ class JsonSchematize::Field
|
|
94
102
|
|
95
103
|
def iterate_array_of_types(value:)
|
96
104
|
return raw_converter_call(value: value) unless array_of_types
|
105
|
+
return empty_value.new if value.nil? && required == false
|
97
106
|
|
98
107
|
unless value.is_a?(Array)
|
99
108
|
raise JsonSchematize::InvalidFieldByArrayOfTypes, ":#{name} expected to be an array based on :array_of_types flag. Given #{value.class}"
|
@@ -10,7 +10,9 @@ class JsonSchematize::Generator
|
|
10
10
|
|
11
11
|
include JsonSchematize::Introspect
|
12
12
|
|
13
|
-
def self.add_field(name:, type: nil, types: nil, dig_type: nil, dig: nil, validator: nil, required: nil, converter: nil, array_of_types: nil, empty_value: nil)
|
13
|
+
def self.add_field(name:, type: nil, types: nil, dig_type: nil, dig: nil, validator: nil, required: nil, converter: nil, array_of_types: nil, empty_value: nil, hash_of_types: nil, hash_of_types_key: "name")
|
14
|
+
require "json_schematize/empty_value"
|
15
|
+
|
14
16
|
field_params = {
|
15
17
|
converter: converter || schema_defaults[:converter],
|
16
18
|
dig: dig || schema_defaults[:dig],
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_schematize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Taylor
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: class_composer
|
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
139
|
- !ruby/object:Gem::Version
|
140
140
|
version: '0'
|
141
141
|
requirements: []
|
142
|
-
rubygems_version: 3.
|
142
|
+
rubygems_version: 3.4.10
|
143
143
|
signing_key:
|
144
144
|
specification_version: 4
|
145
145
|
summary: This gem gives you the ability to turn API results into a standardized schema's
|