json_schematize 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 332c8451a65d8d3ef3c738e6a06d54407e62d479f6d0f015aa348c01c8c70f03
4
- data.tar.gz: 534ae0f9dd57ee349c99fa75305370241470afb99ca0273afe98d9b206a9eb57
3
+ metadata.gz: 41661866a0f6debaa7bacc0897f12f00fe0ee156deb2c18dbacd28ef205a1079
4
+ data.tar.gz: d053b83bc1b4a3fb39b80ad18e126fa535102beeb988e036ab0d76564934af22
5
5
  SHA512:
6
- metadata.gz: ce9ed85a4db89c977231290127487fde0d703ac527009173d28d0d10a1ced80a43d1febcb8cc3e4dff3b64bd80dc20c2817dd14fe301c478d3169342799f1187
7
- data.tar.gz: 6eca9b7c49801e97d1393157c8c49a42ffafcb26bcdc103974329c2222ce3f804a496038f1cf8041836170ac251b3e9f977727f99d4bd11edad6de47931b76de
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.7.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.2.4)
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.1.9)
18
+ concurrent-ruby (1.2.2)
17
19
  diff-lcs (1.5.0)
18
20
  docile (1.4.0)
19
- faker (2.20.0)
21
+ faker (3.1.1)
20
22
  i18n (>= 1.8.11, < 2)
21
- i18n (1.10.0)
23
+ i18n (1.12.0)
22
24
  concurrent-ruby (~> 1.0)
23
25
  method_source (1.0.0)
24
- minitest (5.15.0)
25
- pry (0.13.1)
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.9.0)
30
+ pry-byebug (3.10.1)
29
31
  byebug (~> 11.0)
30
- pry (~> 0.13.0)
32
+ pry (>= 0.13, < 0.15)
31
33
  rake (12.3.3)
32
- rspec (3.11.0)
33
- rspec-core (~> 3.11.0)
34
- rspec-expectations (~> 3.11.0)
35
- rspec-mocks (~> 3.11.0)
36
- rspec-core (3.11.0)
37
- rspec-support (~> 3.11.0)
38
- rspec-expectations (3.11.0)
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.11.0)
41
- rspec-mocks (3.11.0)
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.11.0)
44
- rspec-support (3.11.0)
45
- rspec_junit_formatter (0.5.1)
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.21.2)
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.4)
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.3.8
74
+ 2.4.8
@@ -29,6 +29,8 @@ Gem::Specification.new do |spec|
29
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
30
  spec.require_paths = ["lib"]
31
31
 
32
+ spec.add_dependency "class_composer", "~> 1.0"
33
+
32
34
  spec.add_development_dependency "pry-byebug"
33
35
  spec.add_development_dependency "rake", "~> 12.0"
34
36
  spec.add_development_dependency "rspec", "~> 3.0"
@@ -1,7 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "class_composer"
4
+ require "json_schematize/errors"
5
+
3
6
  module JsonSchematize
4
7
  class Configuration
8
+ include ClassComposer::Generator
9
+
5
10
  DEFAULT_ONE_MIN = 60 * 60
6
11
  DEFAULT_ONE_HOUR = DEFAULT_ONE_MIN * 60
7
12
  DEFAULT_ONE_DAY = DEFAULT_ONE_HOUR * 24
@@ -14,16 +19,11 @@ module JsonSchematize
14
19
  cache_update_on_change: true,
15
20
  }
16
21
 
17
- attr_accessor *DEFAULT_CACHE_OPTIONS.keys
18
-
19
- def initialize
20
- @cache_client = DEFAULT_CACHE_OPTIONS[:cache_client]
21
- @cache_key = DEFAULT_CACHE_OPTIONS[:cache_key]
22
- @cache_namespace = DEFAULT_CACHE_OPTIONS[:cache_namespace]
23
- @cache_stochastic_bust = DEFAULT_CACHE_OPTIONS[:cache_stochastic_bust]
24
- @cache_ttl = DEFAULT_CACHE_OPTIONS[:cache_ttl]
25
- @cache_update_on_change = DEFAULT_CACHE_OPTIONS[:cache_update_on_change]
26
- end
22
+ add_composer :cache_key, allowed: Proc, default: DEFAULT_CACHE_OPTIONS[:cache_key], validation_error_klass: ::JsonSchematize::ConfigError, invalid_message: -> (val) { _assign_msg_("cache_key", "->(val, cusom_key) { val.hash }", "Default proc to assign cache key") }
23
+ add_composer :cache_namespace, allowed: [String, Symbol]
24
+ add_composer :cache_stochastic_bust, allowed: [Float, Integer], default: DEFAULT_CACHE_OPTIONS[:cache_stochastic_bust]
25
+ add_composer :cache_ttl, allowed: [Float, Integer], default: DEFAULT_CACHE_OPTIONS[:cache_ttl]
26
+ add_composer :cache_update_on_change, allowed: [TrueClass, FalseClass], default: DEFAULT_CACHE_OPTIONS[:cache_update_on_change]
27
27
 
28
28
  def cache_hash
29
29
  DEFAULT_CACHE_OPTIONS.map do |key, value|
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JsonSchematize
4
+ class Error < StandardError; end
5
+ class ConfigError < Error; end
6
+ class FieldError < Error; end
7
+
8
+ class InvalidField < Error; end
9
+ class InvalidFieldByValidator < InvalidField; end
10
+ class InvalidFieldByType < InvalidField; end
11
+ class InvalidFieldByArrayOfTypes < InvalidField; end
12
+
13
+ ## Customized class errors
14
+ class UndefinedBoolean < Error; end
15
+ end
@@ -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
- boolean = transformed_value.all? { |val| validate_acceptable_types(val: val) }
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
- boolean = transformed_value.all? { |val| validator.call(transformed_value, raw_value) }
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],
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsonSchematize
4
- VERSION = "0.7.0"
4
+ VERSION = "0.9.0"
5
5
  end
@@ -1,26 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "json_schematize/version"
4
-
5
3
  require "json_schematize/base"
6
4
  require "json_schematize/boolean"
7
5
  require "json_schematize/configuration"
8
6
  require "json_schematize/empty_value"
7
+ require "json_schematize/errors"
9
8
  require "json_schematize/generator"
10
9
  require "json_schematize/version"
11
10
 
12
11
  module JsonSchematize
13
- class Error < StandardError; end
14
- class ConfigError < StandardError; end
15
- class FieldError < Error; end
16
- class InvalidField < Error; end
17
- class InvalidFieldByValidator < InvalidField; end
18
- class InvalidFieldByType < InvalidField; end
19
- class InvalidFieldByArrayOfTypes < InvalidField; end
20
-
21
- ## Customized class errors
22
- class UndefinedBoolean < Error; end
23
-
24
12
  def self.configure
25
13
  yield configuration if block_given?
26
14
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_schematize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.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: 2022-05-07 00:00:00.000000000 Z
11
+ date: 2023-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: class_composer
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: pry-byebug
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -97,6 +111,7 @@ files:
97
111
  - lib/json_schematize/cache/instance_methods.rb
98
112
  - lib/json_schematize/configuration.rb
99
113
  - lib/json_schematize/empty_value.rb
114
+ - lib/json_schematize/errors.rb
100
115
  - lib/json_schematize/field.rb
101
116
  - lib/json_schematize/field_transformations.rb
102
117
  - lib/json_schematize/field_validators.rb
@@ -124,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
139
  - !ruby/object:Gem::Version
125
140
  version: '0'
126
141
  requirements: []
127
- rubygems_version: 3.3.11
142
+ rubygems_version: 3.4.10
128
143
  signing_key:
129
144
  specification_version: 4
130
145
  summary: This gem gives you the ability to turn API results into a standardized schema's