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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6003a56233d3d53c7eb0000e6c96b93a6c4ce737eb810a894fb4096ee1890dcf
4
- data.tar.gz: def4f9ac3e80f7562ac8a71bd15846d281013b973a9daa3ea2ca32ac16d32121
3
+ metadata.gz: 30ba73765eb1eef7075be586554ca29eddc7ae7b81cc293aa526dc47715fbb77
4
+ data.tar.gz: f10b1d7668e6fecd3fc0b8c8a2dcc649df1ede93ce344e2a437209b1d94446c5
5
5
  SHA512:
6
- metadata.gz: a2aadc534091f64fd84b031c97030f4e6739c8ea65ab0d2280644ccff147ec3002ced4236d0ef9d65f4b5ae43ab7fe2e902b336a3f7ee7ababe5e2710e88fafc
7
- data.tar.gz: b6b0382a87707bb66a4e57b804401213914f7792a903d98d61fa3ad4d2c640326822135cc3b435972a36bab38bd6752e27a6447d44ef03fe0200eb522c6245c4
6
+ metadata.gz: a8f5b17a8d1a4d0defb7898b4f8ed2721b960e8b3dbf5216db4ef2dc0d9c56ad9f3d9fe71c67f05735f6838aea729d79d9680614280e142de2f3f2ff17be51c0
7
+ data.tar.gz: 51624964387dcd0f1699827e497f170f31a7ac8d542398ac6fd14cb2d81719cc9c6d018b2dc2178718b6e008e320806b41c3bd77a50f208204a023fb63fae76c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- json_schematize (0.2.0)
4
+ json_schematize (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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!
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsonSchematize
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -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.2.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-08 00:00:00.000000000 Z
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