schemacop 3.0.8 → 3.0.9
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 +4 -4
- data/.releaser_config +1 -1
- data/CHANGELOG.md +6 -0
- data/README_V3.md +36 -0
- data/VERSION +1 -1
- data/lib/schemacop/v3/string_node.rb +8 -2
- data/schemacop.gemspec +29 -17
- data/test/unit/schemacop/v3/string_node_test.rb +47 -0
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8081d63289f1f0078e74dc2d404b549fa5529c2d9ae977fcff713ecd01312f27
|
|
4
|
+
data.tar.gz: aff64b9eb5bc7a9a73a64c2ed0066584cfb59a18dff3566aadcd3c632f8599f8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3084d61eb18f126ce9b88341d0809614f10c5ba74f39ece8fe7f1cc29c9b7f3d3fa89fadd55fe48fa515602bd80d755c326cfc4ce3d4850993d9cbf0e694a48b
|
|
7
|
+
data.tar.gz: b55349b141d1c971923152ecf19793905fc1811bfcb8647271415706d3372bde616d159aa1e8202d4b5630a84443ae6c2d5ccb67acabb5f115db9270b9f0825b
|
data/.releaser_config
CHANGED
data/CHANGELOG.md
CHANGED
data/README_V3.md
CHANGED
|
@@ -208,6 +208,10 @@ transformed into various types.
|
|
|
208
208
|
string values that are commonly used. See section *formats* for more
|
|
209
209
|
information on the available formats. Note that strings with a format are also
|
|
210
210
|
**casted** into that format.
|
|
211
|
+
* `allow_blank`
|
|
212
|
+
By default, blank strings are allowed and left as they are when casted (e.g.
|
|
213
|
+
the string `''` is valid). If you want to disallow blank strings, set this
|
|
214
|
+
option to `false`.
|
|
211
215
|
|
|
212
216
|
#### Formats
|
|
213
217
|
|
|
@@ -247,6 +251,38 @@ transformed into various types.
|
|
|
247
251
|
|
|
248
252
|
#### Examples
|
|
249
253
|
|
|
254
|
+
```ruby
|
|
255
|
+
# Basic example
|
|
256
|
+
schema = Schemacop::Schema3.new :string
|
|
257
|
+
schema.validate!(nil) # => nil
|
|
258
|
+
schema.validate!('') # => ""
|
|
259
|
+
schema.validate!('foo') # => "foo"
|
|
260
|
+
schema.validate!("\n") # => "\n"
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
With the `required` option:
|
|
264
|
+
|
|
265
|
+
```ruby
|
|
266
|
+
# Basic example
|
|
267
|
+
schema = Schemacop::Schema3.new :string, required: true
|
|
268
|
+
schema.validate!(nil) # => Schemacop::Exceptions::ValidationError: /: Value must be given.
|
|
269
|
+
schema.validate!('') # => ""
|
|
270
|
+
schema.validate!('foo') # => "foo"
|
|
271
|
+
schema.validate!("\n") # => "\n"
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
With the `allow_blank` option:
|
|
275
|
+
|
|
276
|
+
```ruby
|
|
277
|
+
# Basic example
|
|
278
|
+
schema = Schemacop::Schema3.new :string, allow_blank: false
|
|
279
|
+
schema.validate!(nil) # => Schemacop::Exceptions::ValidationError: /: String is blank but must not be blank!
|
|
280
|
+
schema.validate!('') # => Schemacop::Exceptions::ValidationError: /: String is blank but must not be blank!
|
|
281
|
+
schema.validate!('foo') # => "foo"
|
|
282
|
+
schema.validate!("\n") # => Schemacop::Exceptions::ValidationError: /: String is blank but must not be blank!
|
|
283
|
+
```
|
|
284
|
+
Example of using a `format` option:
|
|
285
|
+
|
|
250
286
|
```ruby
|
|
251
287
|
# By using a format, string values are casted to that respective format
|
|
252
288
|
schema = Schemacop::Schema3.new(:string, format: :date)
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
3.0.
|
|
1
|
+
3.0.9
|
|
@@ -22,7 +22,7 @@ module Schemacop
|
|
|
22
22
|
# rubocop:enable Layout/LineLength
|
|
23
23
|
|
|
24
24
|
def self.allowed_options
|
|
25
|
-
super + ATTRIBUTES + %i[format_options pattern]
|
|
25
|
+
super + ATTRIBUTES + %i[format_options pattern allow_blank]
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def allowed_types
|
|
@@ -39,6 +39,12 @@ module Schemacop
|
|
|
39
39
|
|
|
40
40
|
def _validate(data, result:)
|
|
41
41
|
super_data = super
|
|
42
|
+
|
|
43
|
+
# Validate blank #
|
|
44
|
+
if options[:allow_blank].is_a?(FalseClass) && super_data.blank?
|
|
45
|
+
result.error 'String is blank but must not be blank!'
|
|
46
|
+
end
|
|
47
|
+
|
|
42
48
|
return if super_data.nil?
|
|
43
49
|
|
|
44
50
|
# Validate length #
|
|
@@ -76,7 +82,7 @@ module Schemacop
|
|
|
76
82
|
end
|
|
77
83
|
|
|
78
84
|
def cast(value)
|
|
79
|
-
if value.
|
|
85
|
+
if !value.nil?
|
|
80
86
|
to_cast = value
|
|
81
87
|
elsif default.present?
|
|
82
88
|
to_cast = default
|
data/schemacop.gemspec
CHANGED
|
@@ -1,37 +1,49 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
-
# stub: schemacop 3.0.
|
|
2
|
+
# stub: schemacop 3.0.9 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.9"
|
|
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-02-
|
|
11
|
+
s.date = "2021-02-26"
|
|
12
12
|
s.files = [".gitignore".freeze, ".releaser_config".freeze, ".rubocop.yml".freeze, ".travis.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]
|
|
15
|
-
s.rubygems_version = "3.
|
|
15
|
+
s.rubygems_version = "3.0.3".freeze
|
|
16
16
|
s.summary = "Schemacop validates ruby structures consisting of nested hashes and arrays against simple schema definitions.".freeze
|
|
17
17
|
s.test_files = ["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]
|
|
18
18
|
|
|
19
19
|
if s.respond_to? :specification_version then
|
|
20
20
|
s.specification_version = 4
|
|
21
|
-
end
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
22
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
23
|
+
s.add_runtime_dependency(%q<activesupport>.freeze, [">= 4.0"])
|
|
24
|
+
s.add_runtime_dependency(%q<ruby2_keywords>.freeze, ["= 0.0.4"])
|
|
25
|
+
s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
|
|
26
|
+
s.add_development_dependency(%q<rake>.freeze, [">= 0"])
|
|
27
|
+
s.add_development_dependency(%q<minitest>.freeze, [">= 0"])
|
|
28
|
+
s.add_development_dependency(%q<minitest-reporters>.freeze, [">= 0"])
|
|
29
|
+
s.add_development_dependency(%q<colorize>.freeze, [">= 0"])
|
|
30
|
+
s.add_development_dependency(%q<rubocop>.freeze, ["= 0.92.0"])
|
|
31
|
+
s.add_development_dependency(%q<pry>.freeze, [">= 0"])
|
|
32
|
+
s.add_development_dependency(%q<byebug>.freeze, [">= 0"])
|
|
33
|
+
s.add_development_dependency(%q<simplecov>.freeze, ["= 0.21.2"])
|
|
34
|
+
else
|
|
35
|
+
s.add_dependency(%q<activesupport>.freeze, [">= 4.0"])
|
|
36
|
+
s.add_dependency(%q<ruby2_keywords>.freeze, ["= 0.0.4"])
|
|
37
|
+
s.add_dependency(%q<bundler>.freeze, [">= 0"])
|
|
38
|
+
s.add_dependency(%q<rake>.freeze, [">= 0"])
|
|
39
|
+
s.add_dependency(%q<minitest>.freeze, [">= 0"])
|
|
40
|
+
s.add_dependency(%q<minitest-reporters>.freeze, [">= 0"])
|
|
41
|
+
s.add_dependency(%q<colorize>.freeze, [">= 0"])
|
|
42
|
+
s.add_dependency(%q<rubocop>.freeze, ["= 0.92.0"])
|
|
43
|
+
s.add_dependency(%q<pry>.freeze, [">= 0"])
|
|
44
|
+
s.add_dependency(%q<byebug>.freeze, [">= 0"])
|
|
45
|
+
s.add_dependency(%q<simplecov>.freeze, ["= 0.21.2"])
|
|
46
|
+
end
|
|
35
47
|
else
|
|
36
48
|
s.add_dependency(%q<activesupport>.freeze, [">= 4.0"])
|
|
37
49
|
s.add_dependency(%q<ruby2_keywords>.freeze, ["= 0.0.4"])
|
|
@@ -400,6 +400,53 @@ module Schemacop
|
|
|
400
400
|
]
|
|
401
401
|
})
|
|
402
402
|
end
|
|
403
|
+
|
|
404
|
+
def test_cast_empty_or_whitespace_string
|
|
405
|
+
schema :string
|
|
406
|
+
|
|
407
|
+
assert_cast(nil, nil)
|
|
408
|
+
assert_cast('', '')
|
|
409
|
+
assert_cast(' ', ' ')
|
|
410
|
+
assert_cast("\n", "\n")
|
|
411
|
+
assert_cast("\t", "\t")
|
|
412
|
+
end
|
|
413
|
+
|
|
414
|
+
def test_cast_empty_or_whitespace_string_required
|
|
415
|
+
schema :string, required: true
|
|
416
|
+
|
|
417
|
+
assert_validation(nil) do
|
|
418
|
+
error '/', 'Value must be given.'
|
|
419
|
+
end
|
|
420
|
+
|
|
421
|
+
assert_cast('', '')
|
|
422
|
+
assert_cast(' ', ' ')
|
|
423
|
+
assert_cast("\n", "\n")
|
|
424
|
+
assert_cast("\t", "\t")
|
|
425
|
+
end
|
|
426
|
+
|
|
427
|
+
def test_empty_or_whitespace_string_blank_not_allowed
|
|
428
|
+
schema :string, allow_blank: false
|
|
429
|
+
|
|
430
|
+
assert_validation(nil) do
|
|
431
|
+
error '/', 'String is blank but must not be blank!'
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
assert_validation('') do
|
|
435
|
+
error '/', 'String is blank but must not be blank!'
|
|
436
|
+
end
|
|
437
|
+
|
|
438
|
+
assert_validation(' ') do
|
|
439
|
+
error '/', 'String is blank but must not be blank!'
|
|
440
|
+
end
|
|
441
|
+
|
|
442
|
+
assert_validation("\n") do
|
|
443
|
+
error '/', 'String is blank but must not be blank!'
|
|
444
|
+
end
|
|
445
|
+
|
|
446
|
+
assert_validation("\t") do
|
|
447
|
+
error '/', 'String is blank but must not be blank!'
|
|
448
|
+
end
|
|
449
|
+
end
|
|
403
450
|
end
|
|
404
451
|
end
|
|
405
452
|
end
|
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.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sitrox
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-02-
|
|
11
|
+
date: 2021-02-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -292,7 +292,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
292
292
|
- !ruby/object:Gem::Version
|
|
293
293
|
version: '0'
|
|
294
294
|
requirements: []
|
|
295
|
-
rubygems_version: 3.
|
|
295
|
+
rubygems_version: 3.0.3
|
|
296
296
|
signing_key:
|
|
297
297
|
specification_version: 4
|
|
298
298
|
summary: Schemacop validates ruby structures consisting of nested hashes and arrays
|