schemacop 3.0.15 → 3.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README_V3.md +24 -1
- data/VERSION +1 -1
- data/lib/schemacop/v3/node.rb +2 -0
- data/lib/schemacop.rb +5 -2
- data/schemacop.gemspec +3 -3
- data/test/unit/schemacop/v3/integer_node_test.rb +5 -0
- data/test/unit/schemacop/v3/node_test.rb +8 -0
- data/test/unit/schemacop/v3/number_node_test.rb +5 -0
- data/test/unit/schemacop/v3/string_node_test.rb +4 -0
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c6c1009f3a4a23a39f58dd1aef99c63136f8d362963d14a7513f08f0d705c0c
|
4
|
+
data.tar.gz: 58a4e7ace82f8f5b1a69ac70ec39dc44a0b4766a167920e3f6de497a7ebe3ee9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7086af3afd13d6cabe140cd550a53b9fed5117b496fb01e67ea4fc9a468d0e5e9a8c5f563fe330fae88a3c4a61fd9c98cbe6317ac1cf6478ab159b66afca9391
|
7
|
+
data.tar.gz: 438129e855a0da9ba74fd7a03c9de3abf3bd206cca4cfe5c70a5ae5ad21d88a927d3cc25738934a3a51f72c32781d48ea1da47c0f7db427a94945792a892641b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## 3.0.17 (2021-12-06)
|
4
|
+
|
5
|
+
* `#64545`: Fix an issue where `cast_str` in conjunction with `number` notes
|
6
|
+
lead to parsing errors when the given number had a leading zero, e.g. parsing
|
7
|
+
the string `08` lead to an error, as the number was interpreted as an octal
|
8
|
+
string. Numbers are now always being treated as decimal with base 10.
|
9
|
+
|
10
|
+
## 3.0.16 (2021-11-23)
|
11
|
+
|
12
|
+
* Add setting `Schemacop.v3_default_options` which allows to set default node
|
13
|
+
options vor V3 schemas. This is particularly useful for the option `cast_str`
|
14
|
+
to allow string casting globally.
|
15
|
+
|
3
16
|
## 3.0.15 (2021-10-11)
|
4
17
|
|
5
18
|
* Add support for custom string formatters
|
data/README_V3.md
CHANGED
@@ -21,6 +21,7 @@
|
|
21
21
|
13. [Reference](#reference)
|
22
22
|
5. [Context](#context)
|
23
23
|
6. [External schemas](#external-schemas)
|
24
|
+
7. [Default options](#default-options)
|
24
25
|
|
25
26
|
## Validation
|
26
27
|
|
@@ -339,6 +340,8 @@ integer can be done.
|
|
339
340
|
When set to `true`, this node also accepts strings that can be casted to an integer, e.g.
|
340
341
|
the values `'-5'` or `'42'`. Please note that you can only validate numbers which
|
341
342
|
are in the `Integer` format. Blank strings will be treated equally as `nil`.
|
343
|
+
Strings will be parsed with base 10, so only decimal numbers are allowed.
|
344
|
+
Leading zeroes will be ignored.
|
342
345
|
|
343
346
|
#### Examples
|
344
347
|
|
@@ -420,7 +423,9 @@ With the various available options, validations on the value of the number can b
|
|
420
423
|
When set to `true`, this node also accepts strings that can be casted to a number, e.g.
|
421
424
|
the values `'0.1'` or `'3.1415'`. Please note that you can only validate numbers which
|
422
425
|
are in the `Integer` or `Float` format, i.e. values like `'1.5r'` or `'(4 + 0i)'` will
|
423
|
-
not work. Blank strings will be treated equally as `nil`.
|
426
|
+
not work. Blank strings will be treated equally as `nil`. Strings will be
|
427
|
+
parsed with base 10, so only decimal numbers are allowed. Leading zeroes will
|
428
|
+
be ignored.
|
424
429
|
|
425
430
|
#### Examples
|
426
431
|
|
@@ -1449,3 +1454,21 @@ Schemacop::V3::GlobalContext.eager_load!
|
|
1449
1454
|
As mentioned before, you can also use the external schemas without having to
|
1450
1455
|
eager-load them, but if you use the schemas multiple times, it might be better
|
1451
1456
|
to eager-load them on start of your application / script.
|
1457
|
+
|
1458
|
+
## Default options
|
1459
|
+
|
1460
|
+
Using the setting `Schemacop.v3_default_options`, you can specify a hash
|
1461
|
+
containing default options that will be used for every schemacop node (options
|
1462
|
+
not supported by a particular node are automatically ignored). Options passed
|
1463
|
+
directly to a node still take precedence. The setting can be set in an
|
1464
|
+
initializer:
|
1465
|
+
|
1466
|
+
```ruby
|
1467
|
+
# config/initializers/schemacop.rb
|
1468
|
+
Schemacop.v3_default_options = { cast_str: true }.freeze
|
1469
|
+
|
1470
|
+
# Example schema: As cast_str is enabled in the default options, strings will
|
1471
|
+
# automatically be casted where supported.
|
1472
|
+
schema = Schemacop::Schema3.new(:integer)
|
1473
|
+
schema.validate!('42') # => 42
|
1474
|
+
```
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.0.
|
1
|
+
3.0.16
|
data/lib/schemacop/v3/node.rb
CHANGED
data/lib/schemacop.rb
CHANGED
@@ -16,6 +16,9 @@ module Schemacop
|
|
16
16
|
mattr_accessor :string_formatters
|
17
17
|
self.string_formatters = {}
|
18
18
|
|
19
|
+
mattr_accessor :v3_default_options
|
20
|
+
self.v3_default_options = {}
|
21
|
+
|
19
22
|
def self.register_string_formatter(name, pattern:, handler:)
|
20
23
|
name = name.to_s.dasherize.to_sym
|
21
24
|
|
@@ -72,7 +75,7 @@ module Schemacop
|
|
72
75
|
register_string_formatter(
|
73
76
|
:integer,
|
74
77
|
pattern: /^-?[0-9]+$/,
|
75
|
-
handler: ->(value) { Integer(value) }
|
78
|
+
handler: ->(value) { Integer(value, 10) }
|
76
79
|
)
|
77
80
|
|
78
81
|
register_string_formatter(
|
@@ -84,7 +87,7 @@ module Schemacop
|
|
84
87
|
register_string_formatter(
|
85
88
|
:'integer-list',
|
86
89
|
pattern: /^(-?[0-9]+)(,-?[0-9]+)*$/,
|
87
|
-
handler: ->(value) { value.split(',').map(
|
90
|
+
handler: ->(value) { value.split(',').map { |i| Integer(i, 10) } }
|
88
91
|
)
|
89
92
|
|
90
93
|
def self.with_context(context)
|
data/schemacop.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: schemacop 3.0.
|
2
|
+
# stub: schemacop 3.0.16 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "schemacop".freeze
|
6
|
-
s.version = "3.0.
|
6
|
+
s.version = "3.0.16"
|
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-
|
11
|
+
s.date = "2021-12-06"
|
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]
|
@@ -181,6 +181,14 @@ module Schemacop
|
|
181
181
|
|
182
182
|
assert_equal(@schema.root.children, [])
|
183
183
|
end
|
184
|
+
|
185
|
+
def test_default_options
|
186
|
+
Schemacop.v3_default_options = { cast_str: true }.freeze
|
187
|
+
schema :number
|
188
|
+
assert_cast('1', 1)
|
189
|
+
ensure
|
190
|
+
Schemacop.v3_default_options = {}
|
191
|
+
end
|
184
192
|
end
|
185
193
|
end
|
186
194
|
end
|
@@ -263,6 +263,10 @@ module Schemacop
|
|
263
263
|
assert_cast '1,-2,3', [1, -2, 3]
|
264
264
|
assert_cast '1', [1]
|
265
265
|
assert_cast '-1', [-1]
|
266
|
+
assert_cast '08', [8]
|
267
|
+
assert_cast '09', [9]
|
268
|
+
assert_cast '050', [50]
|
269
|
+
assert_cast '01,032', [1, 32]
|
266
270
|
end
|
267
271
|
|
268
272
|
def test_format_custom
|
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.
|
4
|
+
version: 3.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sitrox
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -164,8 +164,8 @@ dependencies:
|
|
164
164
|
- - '='
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: 0.21.2
|
167
|
-
description:
|
168
|
-
email:
|
167
|
+
description:
|
168
|
+
email:
|
169
169
|
executables: []
|
170
170
|
extensions: []
|
171
171
|
extra_rdoc_files: []
|
@@ -277,7 +277,7 @@ homepage: https://github.com/sitrox/schemacop
|
|
277
277
|
licenses:
|
278
278
|
- MIT
|
279
279
|
metadata: {}
|
280
|
-
post_install_message:
|
280
|
+
post_install_message:
|
281
281
|
rdoc_options: []
|
282
282
|
require_paths:
|
283
283
|
- lib
|
@@ -292,8 +292,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
292
292
|
- !ruby/object:Gem::Version
|
293
293
|
version: '0'
|
294
294
|
requirements: []
|
295
|
-
rubygems_version: 3.
|
296
|
-
signing_key:
|
295
|
+
rubygems_version: 3.2.22
|
296
|
+
signing_key:
|
297
297
|
specification_version: 4
|
298
298
|
summary: Schemacop validates ruby structures consisting of nested hashes and arrays
|
299
299
|
against simple schema definitions.
|