schemacop 3.0.12 → 3.0.13

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: b89073617fde4588d3cdf44b86c76be5b07c23cf9036c2f44c8b9599dda73779
4
- data.tar.gz: 5d3860807fc84a14043dda84a2bdf7fc5696668171b2bc5560607f3de14be242
3
+ metadata.gz: 86a824c8ccca5369721dff7f7ccebb581cb34685a31aa50126444a92593ee20c
4
+ data.tar.gz: a336258896003d683a4b9b3d5c8a1a7e5070c1cef06eb4975ba0ba8d872c8f0a
5
5
  SHA512:
6
- metadata.gz: 63a492f2523c049f3a720ca9525d72ddf15e76a3e092dcb3b295af118fe2a1cd1e0cc92c8dffb4c20f1e5e7b98c466efde3d96dd26180279ffad9ab27157948f
7
- data.tar.gz: f06fd83b902c3fa67ef554fd47930b39dbdfa77f57e753d14b74b88b23fe32da5043cdebc563d4296e80af53118505420f3f0d6d88f122554891fa8e2e3ca048
6
+ metadata.gz: f4faf09edddbbd5fa892ee9b7f4dc75a0e551744e625f2b8552fe68678113abfd07dc2b8f3344f0d75c7f37aa84281b7c37195f8dd9aa70b2b89e5742a98452c
7
+ data.tar.gz: 2f07ee47aba8a6147a6088f7f3fe6e0c35168b9a59ee540c00cd3f8693104b74e74227fa68c96604410098d774ea9774c50f135f20a51448f349b8b297d4a2f1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Change log
2
2
 
3
+ ## 3.0.13 (2021-10-04)
4
+
5
+ * When using `boolean` with `cast_str: true`, `"0"` is now casted to `false` and
6
+ `"1"` to `true`. This in addition to already casting `"true", "false"`.
7
+
3
8
  ## 3.0.12 (2021-09-14)
4
9
 
5
10
  * Fix compatibility issue with `ruby <= 2.5`
data/README_V3.md CHANGED
@@ -233,8 +233,8 @@ transformed into various types.
233
233
  addresses do not have their own ruby type.
234
234
 
235
235
  * `boolean`
236
- The string must be either `true` or `false`. This value will be casted to
237
- Ruby's `TrueClass` or `FalseClass`.
236
+ The string must be either `true`, `false`, `0` or `1`. This value will be
237
+ casted to Ruby's `TrueClass` or `FalseClass`.
238
238
 
239
239
  * `binary`
240
240
  The string is expected to contain binary contents. No casting or additional
@@ -501,8 +501,9 @@ The boolean type is used to validate Ruby booleans, i.e. the `TrueClass` and `Fa
501
501
  #### Options
502
502
 
503
503
  * `cast_str`
504
- When set to `true`, this node also accepts strings that can be casted to a boolean, i.e.
505
- the values `'true'` and `'false'`. Blank strings will be treated equally as `nil`.
504
+ When set to `true`, this node also accepts strings that can be casted to a
505
+ boolean, namely the values `'true'`, `'false'`, `'1'` and `'0'`. Blank strings
506
+ will be treated equally as `nil`.
506
507
 
507
508
  #### Examples
508
509
 
@@ -514,6 +515,11 @@ schema.validate!(false) # => false
514
515
  schema.validate!(:false) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "Symbol", expected "boolean".
515
516
  schema.validate!('false') # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "String", expected "boolean".
516
517
  schema.validate!(1234) # => Schemacop::Exceptions::ValidationError: /: Invalid type, got type "Integer", expected "boolean".
518
+
519
+ schema.validate!('0', cast_str: true) # => false
520
+ schema.validate!('1', cast_str: true) # => true
521
+ schema.validate!('false', cast_str: true) # => false
522
+ schema.validate!('true', cast_str: true) # => true
517
523
  ```
518
524
 
519
525
  With `cast_str` enabled:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.12
1
+ 3.0.13
@@ -13,7 +13,7 @@ module Schemacop
13
13
  'date-time': /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)?(Z|[+-](?:2[0-3]|[01][0-9]):[0-5][0-9])?$/,
14
14
  time: /^(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)?(Z|[+-](?:2[0-3]|[01][0-9]):[0-5][0-9])?$/,
15
15
  email: URI::MailTo::EMAIL_REGEXP,
16
- boolean: /^(true|false)$/,
16
+ boolean: /^(true|false|0|1)$/,
17
17
  binary: nil,
18
18
  symbol: nil,
19
19
  integer: /^-?[0-9]+$/,
@@ -92,7 +92,7 @@ module Schemacop
92
92
 
93
93
  case options[:format]
94
94
  when :boolean
95
- return to_cast == 'true'
95
+ return to_cast == 'true' || to_cast == '1'
96
96
  when :date
97
97
  return Date.parse(to_cast)
98
98
  when :'date-time'
data/schemacop.gemspec CHANGED
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: schemacop 3.0.12 ruby lib
2
+ # stub: schemacop 3.0.13 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "schemacop".freeze
6
- s.version = "3.0.12"
6
+ s.version = "3.0.13"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["Sitrox".freeze]
11
- s.date = "2021-09-14"
11
+ s.date = "2021-10-04"
12
12
  s.files = [".github/workflows/ruby.yml".freeze, ".gitignore".freeze, ".releaser_config".freeze, ".rubocop.yml".freeze, ".yardopts".freeze, "CHANGELOG.md".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "README_V2.md".freeze, "README_V3.md".freeze, "RUBY_VERSION".freeze, "Rakefile".freeze, "VERSION".freeze, "lib/schemacop.rb".freeze, "lib/schemacop/base_schema.rb".freeze, "lib/schemacop/exceptions.rb".freeze, "lib/schemacop/railtie.rb".freeze, "lib/schemacop/schema.rb".freeze, "lib/schemacop/schema2.rb".freeze, "lib/schemacop/schema3.rb".freeze, "lib/schemacop/scoped_env.rb".freeze, "lib/schemacop/v2.rb".freeze, "lib/schemacop/v2/caster.rb".freeze, "lib/schemacop/v2/collector.rb".freeze, "lib/schemacop/v2/dupper.rb".freeze, "lib/schemacop/v2/field_node.rb".freeze, "lib/schemacop/v2/node.rb".freeze, "lib/schemacop/v2/node_resolver.rb".freeze, "lib/schemacop/v2/node_supporting_field.rb".freeze, "lib/schemacop/v2/node_supporting_type.rb".freeze, "lib/schemacop/v2/node_with_block.rb".freeze, "lib/schemacop/v2/validator/array_validator.rb".freeze, "lib/schemacop/v2/validator/boolean_validator.rb".freeze, "lib/schemacop/v2/validator/float_validator.rb".freeze, "lib/schemacop/v2/validator/hash_validator.rb".freeze, "lib/schemacop/v2/validator/integer_validator.rb".freeze, "lib/schemacop/v2/validator/nil_validator.rb".freeze, "lib/schemacop/v2/validator/number_validator.rb".freeze, "lib/schemacop/v2/validator/object_validator.rb".freeze, "lib/schemacop/v2/validator/string_validator.rb".freeze, "lib/schemacop/v2/validator/symbol_validator.rb".freeze, "lib/schemacop/v3.rb".freeze, "lib/schemacop/v3/all_of_node.rb".freeze, "lib/schemacop/v3/any_of_node.rb".freeze, "lib/schemacop/v3/array_node.rb".freeze, "lib/schemacop/v3/boolean_node.rb".freeze, "lib/schemacop/v3/combination_node.rb".freeze, "lib/schemacop/v3/context.rb".freeze, "lib/schemacop/v3/dsl_scope.rb".freeze, "lib/schemacop/v3/global_context.rb".freeze, "lib/schemacop/v3/hash_node.rb".freeze, "lib/schemacop/v3/integer_node.rb".freeze, "lib/schemacop/v3/is_not_node.rb".freeze, "lib/schemacop/v3/node.rb".freeze, "lib/schemacop/v3/node_registry.rb".freeze, "lib/schemacop/v3/number_node.rb".freeze, "lib/schemacop/v3/numeric_node.rb".freeze, "lib/schemacop/v3/object_node.rb".freeze, "lib/schemacop/v3/one_of_node.rb".freeze, "lib/schemacop/v3/reference_node.rb".freeze, "lib/schemacop/v3/result.rb".freeze, "lib/schemacop/v3/string_node.rb".freeze, "lib/schemacop/v3/symbol_node.rb".freeze, "schemacop.gemspec".freeze, "test/lib/test_helper.rb".freeze, "test/schemas/nested/group.rb".freeze, "test/schemas/user.rb".freeze, "test/unit/schemacop/v2/casting_test.rb".freeze, "test/unit/schemacop/v2/collector_test.rb".freeze, "test/unit/schemacop/v2/custom_check_test.rb".freeze, "test/unit/schemacop/v2/custom_if_test.rb".freeze, "test/unit/schemacop/v2/defaults_test.rb".freeze, "test/unit/schemacop/v2/empty_test.rb".freeze, "test/unit/schemacop/v2/nil_dis_allow_test.rb".freeze, "test/unit/schemacop/v2/node_resolver_test.rb".freeze, "test/unit/schemacop/v2/short_forms_test.rb".freeze, "test/unit/schemacop/v2/types_test.rb".freeze, "test/unit/schemacop/v2/validator_array_test.rb".freeze, "test/unit/schemacop/v2/validator_boolean_test.rb".freeze, "test/unit/schemacop/v2/validator_float_test.rb".freeze, "test/unit/schemacop/v2/validator_hash_test.rb".freeze, "test/unit/schemacop/v2/validator_integer_test.rb".freeze, "test/unit/schemacop/v2/validator_nil_test.rb".freeze, "test/unit/schemacop/v2/validator_number_test.rb".freeze, "test/unit/schemacop/v2/validator_object_test.rb".freeze, "test/unit/schemacop/v2/validator_string_test.rb".freeze, "test/unit/schemacop/v2/validator_symbol_test.rb".freeze, "test/unit/schemacop/v3/all_of_node_test.rb".freeze, "test/unit/schemacop/v3/any_of_node_test.rb".freeze, "test/unit/schemacop/v3/array_node_test.rb".freeze, "test/unit/schemacop/v3/boolean_node_test.rb".freeze, "test/unit/schemacop/v3/global_context_test.rb".freeze, "test/unit/schemacop/v3/hash_node_test.rb".freeze, "test/unit/schemacop/v3/integer_node_test.rb".freeze, "test/unit/schemacop/v3/is_not_node_test.rb".freeze, "test/unit/schemacop/v3/node_test.rb".freeze, "test/unit/schemacop/v3/number_node_test.rb".freeze, "test/unit/schemacop/v3/object_node_test.rb".freeze, "test/unit/schemacop/v3/one_of_node_test.rb".freeze, "test/unit/schemacop/v3/reference_node_test.rb".freeze, "test/unit/schemacop/v3/string_node_test.rb".freeze, "test/unit/schemacop/v3/symbol_node_test.rb".freeze]
13
13
  s.homepage = "https://github.com/sitrox/schemacop".freeze
14
14
  s.licenses = ["MIT".freeze]
@@ -146,10 +146,13 @@ module Schemacop
146
146
  assert_cast('true', true)
147
147
  assert_cast('false', false)
148
148
 
149
+ assert_cast('1', true)
150
+ assert_cast('0', false)
151
+
149
152
  assert_cast(true, true)
150
153
  assert_cast(false, false)
151
154
 
152
- assert_validation('1') do
155
+ assert_validation('5') do
153
156
  error '/', 'Matches 0 definitions but should match exactly 1.'
154
157
  end
155
158
 
@@ -171,7 +174,11 @@ module Schemacop
171
174
  assert_cast(true, true)
172
175
  assert_cast(false, false)
173
176
 
174
- assert_validation('1') do
177
+ assert_validation('4') do
178
+ error '/', 'Matches 0 definitions but should match exactly 1.'
179
+ end
180
+
181
+ assert_validation('foo') do
175
182
  error '/', 'Matches 0 definitions but should match exactly 1.'
176
183
  end
177
184
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schemacop
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.12
4
+ version: 3.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sitrox
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-14 00:00:00.000000000 Z
11
+ date: 2021-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport