json_schematize 0.2.0 → 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/Gemfile.lock +1 -1
- data/README.md +7 -0
- data/lib/json_schematize/boolean.rb +13 -0
- data/lib/json_schematize/generator.rb +3 -3
- data/lib/json_schematize/version.rb +1 -1
- data/lib/json_schematize.rb +4 -0
- 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: 30ba73765eb1eef7075be586554ca29eddc7ae7b81cc293aa526dc47715fbb77
|
4
|
+
data.tar.gz: f10b1d7668e6fecd3fc0b8c8a2dcc649df1ede93ce344e2a437209b1d94446c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8f5b17a8d1a4d0defb7898b4f8ed2721b960e8b3dbf5216db4ef2dc0d9c56ad9f3d9fe71c67f05735f6838aea729d79d9680614280e142de2f3f2ff17be51c0
|
7
|
+
data.tar.gz: 51624964387dcd0f1699827e497f170f31a7ac8d542398ac6fd14cb2d81719cc9c6d018b2dc2178718b6e008e320806b41c3bd77a50f208204a023fb63fae76c
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -85,7 +85,14 @@ required -- Default is true. When not set, each instance class can optionally de
|
|
85
85
|
converter -- Proc return is set to the field value. No furter validation is done. Given (value) as a parameter
|
86
86
|
array_of_types -- Detailed example above. Set this value to true when the dig param is to an array and you want all values in array to be parsed the given type
|
87
87
|
```
|
88
|
+
### Custom Classes
|
88
89
|
|
90
|
+
```ruby
|
91
|
+
class CustomClasses < JsonSchematize::Generator
|
92
|
+
# JsonSchematize::Boolean can be used as a type when expecting a conversion of possible true or false values converted into a TrueClass or FalseClass
|
93
|
+
add_field name: :internals, type: JsonSchematize::Boolean
|
94
|
+
end
|
95
|
+
```
|
89
96
|
|
90
97
|
## Development
|
91
98
|
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class JsonSchematize::Boolean
|
4
|
+
FALSE_VALUES = ["false", "f", "0", false]
|
5
|
+
TRUE_VALUES = ["true", "t", "1", true]
|
6
|
+
|
7
|
+
def self.new(val)
|
8
|
+
return false if FALSE_VALUES.include?(val)
|
9
|
+
return true if TRUE_VALUES.include?(val)
|
10
|
+
|
11
|
+
raise JsonSchematize::UndefinedBoolean, "#{val} is not a valid #{self.class}"
|
12
|
+
end
|
13
|
+
end
|
@@ -67,9 +67,9 @@ class JsonSchematize::Generator
|
|
67
67
|
|
68
68
|
attr_reader :__raw_params, :raise_on_error
|
69
69
|
|
70
|
-
|
71
|
-
def initialize(raise_on_error: true, **params)
|
72
|
-
@__params = params
|
70
|
+
# stringified_params allows for params with stringed keys
|
71
|
+
def initialize(stringified_params = {}, raise_on_error: true, **params)
|
72
|
+
@__params = stringified_params.empty? ? params : stringified_params
|
73
73
|
@raise_on_error = raise_on_error
|
74
74
|
|
75
75
|
validate_required!
|
data/lib/json_schematize.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require "json_schematize/version"
|
4
4
|
require "json_schematize/generator"
|
5
|
+
require "json_schematize/boolean"
|
5
6
|
|
6
7
|
module JsonSchematize
|
7
8
|
class Error < StandardError; end
|
@@ -10,4 +11,7 @@ module JsonSchematize
|
|
10
11
|
class InvalidFieldByValidator < InvalidField; end
|
11
12
|
class InvalidFieldByType < InvalidField; end
|
12
13
|
class InvalidFieldByArrayOfTypes < InvalidField; end
|
14
|
+
|
15
|
+
## Customized class errors
|
16
|
+
class UndefinedBoolean < Error; end
|
13
17
|
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.
|
4
|
+
version: 0.3.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: 2022-03-
|
11
|
+
date: 2022-03-10 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/boolean.rb
|
91
92
|
- lib/json_schematize/field.rb
|
92
93
|
- lib/json_schematize/field_transformations.rb
|
93
94
|
- lib/json_schematize/field_validators.rb
|