json_schematize 0.3.0 → 0.3.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
- data/Gemfile.lock +1 -1
- data/lib/json_schematize/base.rb +7 -0
- data/lib/json_schematize/boolean.rb +7 -1
- data/lib/json_schematize/field.rb +14 -2
- data/lib/json_schematize/version.rb +1 -1
- data/lib/json_schematize.rb +3 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 545006e10e9c73489b4a2db37d7b787a49c4427dd58d541ac938bad4c73954ce
|
4
|
+
data.tar.gz: 38f4d89c9cb2ffc8b9863531d8745eae5acd2b2bc1379ea6e9f459d66550525e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d640bd68de88a3e6e3b4a73fd8688e9c017bbb8948a73abb3a2f4bf36a87c3ba1bd31bb08f052b8fd36bca9a7758f825f32448ae39930610eaae7323ccd336fb
|
7
|
+
data.tar.gz: 344f9dd96df21d5b5f8f8b6daca078281403606c5b75dcc958d999186380e83a56ddb592f071b271656882ad9d4a117ce7211ca050cb901e4f57fbb90fe2355e
|
data/Gemfile.lock
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require "json_schematize/base"
|
4
|
+
|
5
|
+
class JsonSchematize::Boolean < JsonSchematize::Base
|
4
6
|
FALSE_VALUES = ["false", "f", "0", false]
|
5
7
|
TRUE_VALUES = ["true", "t", "1", true]
|
6
8
|
|
@@ -10,4 +12,8 @@ class JsonSchematize::Boolean
|
|
10
12
|
|
11
13
|
raise JsonSchematize::UndefinedBoolean, "#{val} is not a valid #{self.class}"
|
12
14
|
end
|
15
|
+
|
16
|
+
def self.acceptable_types
|
17
|
+
[TrueClass, FalseClass]
|
18
|
+
end
|
13
19
|
end
|
@@ -36,9 +36,9 @@ class JsonSchematize::Field
|
|
36
36
|
|
37
37
|
def acceptable_value?(transformed_value:, raise_on_error:)
|
38
38
|
if array_of_types
|
39
|
-
boolean = transformed_value.all? { |val|
|
39
|
+
boolean = transformed_value.all? { |val| validate_acceptable_types(val: val) }
|
40
40
|
else
|
41
|
-
boolean =
|
41
|
+
boolean = validate_acceptable_types(val: transformed_value)
|
42
42
|
end
|
43
43
|
|
44
44
|
if raise_on_error && (boolean==false)
|
@@ -77,6 +77,18 @@ class JsonSchematize::Field
|
|
77
77
|
|
78
78
|
private
|
79
79
|
|
80
|
+
def validate_acceptable_types(val:)
|
81
|
+
(all_allowed_types + @acceptable_types).include?(val.class)
|
82
|
+
end
|
83
|
+
|
84
|
+
def all_allowed_types
|
85
|
+
@all_allowed_types ||= begin
|
86
|
+
@acceptable_types.map do |t|
|
87
|
+
t.acceptable_types if t.ancestors.include?(JsonSchematize::Base)
|
88
|
+
end.compact.flatten
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
80
92
|
def iterate_array_of_types(value:)
|
81
93
|
return raw_converter_call(value: value) unless array_of_types
|
82
94
|
|
data/lib/json_schematize.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "json_schematize/
|
4
|
-
require "json_schematize/generator"
|
3
|
+
require "json_schematize/base"
|
5
4
|
require "json_schematize/boolean"
|
5
|
+
require "json_schematize/generator"
|
6
|
+
require "json_schematize/version"
|
6
7
|
|
7
8
|
module JsonSchematize
|
8
9
|
class Error < StandardError; end
|
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.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Taylor
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry-byebug
|
@@ -88,6 +88,7 @@ files:
|
|
88
88
|
- docker-compose.yml
|
89
89
|
- json_schematize.gemspec
|
90
90
|
- lib/json_schematize.rb
|
91
|
+
- lib/json_schematize/base.rb
|
91
92
|
- lib/json_schematize/boolean.rb
|
92
93
|
- lib/json_schematize/field.rb
|
93
94
|
- lib/json_schematize/field_transformations.rb
|