schemacop 3.0.7 → 3.0.8

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: 85c1da35631e2529c91caa46f76c5784ad51fd83843eb1126912919b36c96809
4
- data.tar.gz: e1315e5f708c804f329d79fe76c2a22ac9e2179dc3ddf5301ebcbbe280028638
3
+ metadata.gz: f11e7ce866105fc0749471f503ec88accb8307fdbef31ed417b675e29fa1141e
4
+ data.tar.gz: 400dfe76003e347560eaab180a6df3df073bc8ec1930edad3395331c494ce6e8
5
5
  SHA512:
6
- metadata.gz: f3de1743f921b7c09914d9d8f483ebe05fceb4055671b9d7413302ae0eb442a1b6c5b9c073e82eee43cd94e98c26c055b641677d154b0f515930aabae00a7714
7
- data.tar.gz: 0c48ce6c72444da2702f1e4a927ffbc4533dea8abbf40f7065fa929be7a4b9ac49d788612550ca587ea6b16be1d24691814f9dec2bc81d7d27aeb48690e32be4
6
+ metadata.gz: 5bd90d0c7de2ca4c48626b6410eb8f7711a8ad6e179e1a4f96ac92890da8f2cac113ec495ff1af7335365a0e32ea7f528ce7f141a7973f5c7779615ab84929b7
7
+ data.tar.gz: f6dee225eecc7ae469ac1162f08b2a6108bc5625629077b317e0b378bd6dd953417d6d5b463fdb62ad1ee8a61275a8cca7eabad4862abfff27503b5d998328f5
data/.releaser_config CHANGED
@@ -1,3 +1,4 @@
1
1
  version_file: VERSION
2
2
  always_from_master: true
3
3
  gem_style: github
4
+ ruby_command: ruby -S
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change log
2
2
 
3
+ ## 3.0.8 (2021-02-23)
4
+
5
+ * Fix `object` nodes in hashes with no classes
6
+
7
+ * Document `cast_str` option
8
+
3
9
  ## 3.0.7 (2021-02-22)
4
10
 
5
11
  * Adapt schema definitions handling when using Swagger-standard JSON
data/README_V3.md CHANGED
@@ -199,9 +199,10 @@ transformed into various types.
199
199
  * `max_length`
200
200
  Defines the (inclusive) maximum required string length
201
201
  * `pattern`
202
- Defines a (ruby) regex pattern the value will be matched against. Must be a
203
- string and should generally start with `^` and end with `$` so as to evaluate
204
- the entire string. It should not be enclosed in `/` characters.
202
+ Defines a (ruby) regex pattern the value will be matched against. Must be either
203
+ a string which should not be enclosed in `/` characters, or a Ruby Regexp.
204
+ The pattern should generally start with `^` and end with `$` so as to evaluate
205
+ the entire string.
205
206
  * `format`
206
207
  The `format` option allows for basic semantic validation on certain kinds of
207
208
  string values that are commonly used. See section *formats* for more
@@ -277,6 +278,10 @@ integer can be done.
277
278
  * `multiple_of`
278
279
  The received number has to be a multiple of the given number for the validation to
279
280
  pass.
281
+ * `cast_str`
282
+ When set to `true`, this node also accepts strings that can be casted to an integer, e.g.
283
+ the values `'-5'` or `'42'`. Please note that you can only validate numbers which
284
+ are in the `Integer` format.
280
285
 
281
286
  #### Examples
282
287
 
@@ -293,6 +298,20 @@ schema.validate!((4 + 0i)) # => Schemacop::Exceptions::ValidationError: /:
293
298
  schema.validate!(BigDecimal(5)) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "integer".
294
299
  ```
295
300
 
301
+ With `cast_str` enabled:
302
+
303
+ ```ruby
304
+ # Validates that the input is an even number between 0 and 100 (inclusive)
305
+ schema = Schemacop::Schema3.new(:integer, minimum: 0, maximum: 100, multiple_of: 2, cast_str: true)
306
+ schema.validate!('42') # => 42
307
+ schema.validate!('43') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1.
308
+ schema.validate!('-2') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1.
309
+ schema.validate!('102') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1.
310
+ schema.validate!('42.1') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1.
311
+ schema.validate!('4r') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1.
312
+ schema.validate!('(4 + 0i)') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1.
313
+ ```
314
+
296
315
  ### Number
297
316
 
298
317
  Type: `:number`\
@@ -327,6 +346,11 @@ With the various available options, validations on the value of the number can b
327
346
  * `multiple_of`
328
347
  The received number has to be a multiple of the given number for the validation to
329
348
  pass.
349
+ * `cast_str`
350
+ When set to `true`, this node also accepts strings that can be casted to a number, e.g.
351
+ the values `'0.1'` or `'3.1415'`. Please note that you can only validate numbers which
352
+ are in the `Integer` or `Float` format, i.e. values like `'1.5r'` or `'(4 + 0i)'` will
353
+ not work.
330
354
 
331
355
  #### Examples
332
356
 
@@ -343,6 +367,19 @@ schema.validate!(BigDecimal(5)) # => 0.5e1
343
367
  schema.validate!((4 + 0i)) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "big_decimal" or "float" or "integer" or "rational".
344
368
  ```
345
369
 
370
+ With `cast_str` enabled:
371
+
372
+ ```ruby
373
+ schema = Schemacop::Schema3.new(:number, cast_str: true, minimum: 0.0, maximum: (50r), multiple_of: BigDecimal('0.5'))
374
+ schema.validate!('42') # => 42
375
+ schema.validate!('42.2') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1.
376
+ schema.validate!('-2') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1.
377
+ schema.validate!('51') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1.
378
+ schema.validate!('42.5') # => 42.5
379
+ schema.validate!('1.5r') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1.
380
+ schema.validate!('(4 + 0i)') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1.
381
+ ```
382
+
346
383
  ### Symbol
347
384
 
348
385
  Type: `:symbol`\
@@ -350,15 +387,33 @@ DSL: `sym`
350
387
 
351
388
  The symbol type is used to validate elements for the Ruby `Symbol` class.
352
389
 
390
+ #### Options
391
+
392
+ * `cast_str`
393
+ When set to `true`, this node also accepts strings that can be casted to a symbol.
394
+
353
395
  #### Examples
354
396
 
355
397
  ```ruby
356
398
  # Validates that the input is a symbol
357
399
  schema = Schemacop::Schema3.new(:symbol)
358
- schema.validate!(:foo) # => :foo
359
- schema.validate!('foo') # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "Symbol".
360
- schema.validate!(123) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "Symbol".
361
- schema.validate!(false) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "Symbol".
400
+ schema.validate!(:foo) # => :foo
401
+ schema.validate!('foo') # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "Symbol".
402
+ schema.validate!(123) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "Symbol".
403
+ schema.validate!(false) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "Symbol".
404
+ schema.validate!(:false) # => :false
405
+ ```
406
+
407
+ With `cast_str` enabled:
408
+
409
+ ```ruby
410
+ # Validates that the input is a symbol
411
+ schema = Schemacop::Schema3.new(:symbol, cast_str: true)
412
+ schema.validate!(':foo') # => :":foo"
413
+ schema.validate!('foo') # => :foo
414
+ schema.validate!('123') # => :"123"
415
+ schema.validate!('false') # => :false
416
+ schema.validate!(':false') # => :":false"
362
417
  ```
363
418
 
364
419
  ### Boolean
@@ -368,6 +423,12 @@ DSL: `boo`
368
423
 
369
424
  The boolean type is used to validate Ruby booleans, i.e. the `TrueClass` and `FalseClass`
370
425
 
426
+ #### Options
427
+
428
+ * `cast_str`
429
+ When set to `true`, this node also accepts strings that can be casted to a boolean, i.e.
430
+ the values `'true'` and `'false'`
431
+
371
432
  #### Examples
372
433
 
373
434
  ```ruby
@@ -380,6 +441,17 @@ schema.validate!('false') # => Schemacop::Exceptions::ValidationError: /: Invali
380
441
  schema.validate!(1234) # => Schemacop::Exceptions::ValidationError: /: Invalid type, expected "boolean".
381
442
  ```
382
443
 
444
+ With `cast_str` enabled:
445
+
446
+ ```ruby
447
+ schema = Schemacop::Schema3.new(:boolean, cast_str: true)
448
+ schema.validate!(true) # => true
449
+ schema.validate!(false) # => false
450
+ schema.validate!(:false) # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1.
451
+ schema.validate!('false') # => false
452
+ schema.validate!(1234) # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1.
453
+ ```
454
+
383
455
  ### Array
384
456
 
385
457
  Type: `:array`\
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.7
1
+ 3.0.8
@@ -19,6 +19,10 @@ module Schemacop
19
19
  default
20
20
  end
21
21
  end
22
+
23
+ def self.allowed_options
24
+ super + %i[cast_str]
25
+ end
22
26
  end
23
27
  end
24
28
  end
@@ -48,7 +48,7 @@ module Schemacop
48
48
  end
49
49
 
50
50
  def self.allowed_options
51
- %i[name required default description examples enum parent options cast_str title as]
51
+ %i[name required default description examples enum parent options title as]
52
52
  end
53
53
 
54
54
  def self.dsl_methods
@@ -11,7 +11,7 @@ module Schemacop
11
11
  ].freeze
12
12
 
13
13
  def self.allowed_options
14
- super + ATTRIBUTES
14
+ super + ATTRIBUTES + %i[cast_str]
15
15
  end
16
16
 
17
17
  def process_json(attrs, json)
@@ -5,11 +5,6 @@ module Schemacop
5
5
  super + %i[classes strict]
6
6
  end
7
7
 
8
- def self.create(classes, **options, &block)
9
- options[:classes] = classes
10
- super(**options, &block)
11
- end
12
-
13
8
  def as_json
14
9
  {} # Not supported by Json Schema
15
10
  end
@@ -22,7 +22,7 @@ module Schemacop
22
22
  # rubocop:enable Layout/LineLength
23
23
 
24
24
  def self.allowed_options
25
- super + ATTRIBUTES - %i[cast_str] + %i[format_options pattern]
25
+ super + ATTRIBUTES + %i[format_options pattern]
26
26
  end
27
27
 
28
28
  def allowed_types
@@ -8,6 +8,10 @@ module Schemacop
8
8
  def allowed_types
9
9
  { Symbol => 'Symbol' }
10
10
  end
11
+
12
+ def self.allowed_options
13
+ super + %i[cast_str]
14
+ end
11
15
  end
12
16
  end
13
17
  end
data/schemacop.gemspec CHANGED
@@ -1,49 +1,37 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: schemacop 3.0.7 ruby lib
2
+ # stub: schemacop 3.0.8 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "schemacop".freeze
6
- s.version = "3.0.7"
6
+ s.version = "3.0.8"
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-22"
11
+ s.date = "2021-02-23"
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.0.3".freeze
15
+ s.rubygems_version = "3.1.2".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
21
22
 
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
23
+ if s.respond_to? :add_runtime_dependency then
24
+ s.add_runtime_dependency(%q<activesupport>.freeze, [">= 4.0"])
25
+ s.add_runtime_dependency(%q<ruby2_keywords>.freeze, ["= 0.0.4"])
26
+ s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
27
+ s.add_development_dependency(%q<rake>.freeze, [">= 0"])
28
+ s.add_development_dependency(%q<minitest>.freeze, [">= 0"])
29
+ s.add_development_dependency(%q<minitest-reporters>.freeze, [">= 0"])
30
+ s.add_development_dependency(%q<colorize>.freeze, [">= 0"])
31
+ s.add_development_dependency(%q<rubocop>.freeze, ["= 0.92.0"])
32
+ s.add_development_dependency(%q<pry>.freeze, [">= 0"])
33
+ s.add_development_dependency(%q<byebug>.freeze, [">= 0"])
34
+ s.add_development_dependency(%q<simplecov>.freeze, ["= 0.21.2"])
47
35
  else
48
36
  s.add_dependency(%q<activesupport>.freeze, [">= 4.0"])
49
37
  s.add_dependency(%q<ruby2_keywords>.freeze, ["= 0.0.4"])
@@ -73,8 +73,8 @@ module Schemacop
73
73
  hsh { str! :foo }
74
74
  end
75
75
  any_of do
76
- obj(Date)
77
- obj(Time)
76
+ obj classes: Date
77
+ obj classes: Time
78
78
  end
79
79
  ary
80
80
  boo
@@ -136,6 +136,20 @@ module Schemacop
136
136
  assert_cast(false, false)
137
137
  assert_cast(nil, true)
138
138
  end
139
+
140
+ def test_cast_str
141
+ schema :boolean, cast_str: true
142
+
143
+ assert_cast('true', true)
144
+ assert_cast('false', false)
145
+
146
+ assert_cast(true, true)
147
+ assert_cast(false, false)
148
+
149
+ assert_validation('1') do
150
+ error '/', 'Matches 0 definitions but should match exactly 1.'
151
+ end
152
+ end
139
153
  end
140
154
  end
141
155
  end
@@ -330,6 +330,17 @@ module Schemacop
330
330
  ]
331
331
  })
332
332
  end
333
+
334
+ def test_cast_str
335
+ schema :integer, cast_str: true
336
+
337
+ assert_cast('1', 1)
338
+ assert_cast(1, 1)
339
+
340
+ assert_validation('true') do
341
+ error '/', 'Matches 0 definitions but should match exactly 1.'
342
+ end
343
+ end
333
344
  end
334
345
  end
335
346
  end
@@ -299,6 +299,35 @@ module Schemacop
299
299
  ]
300
300
  })
301
301
  end
302
+
303
+ def test_cast_str
304
+ schema :number, cast_str: true, minimum: 0.0, maximum: 50r, multiple_of: BigDecimal('0.5')
305
+
306
+ assert_cast('1', 1)
307
+ assert_cast(1, 1)
308
+
309
+ assert_cast('1.0', 1.0)
310
+ assert_cast(1.0, 1.0)
311
+
312
+ assert_validation('42')
313
+ assert_validation('0.5')
314
+
315
+ assert_validation('true') do
316
+ error '/', 'Matches 0 definitions but should match exactly 1.'
317
+ end
318
+
319
+ assert_validation('51') do
320
+ error '/', 'Matches 0 definitions but should match exactly 1.'
321
+ end
322
+
323
+ assert_validation('-2') do
324
+ error '/', 'Matches 0 definitions but should match exactly 1.'
325
+ end
326
+
327
+ assert_validation('3.1415') do
328
+ error '/', 'Matches 0 definitions but should match exactly 1.'
329
+ end
330
+ end
302
331
  end
303
332
  end
304
333
  end
@@ -59,7 +59,10 @@ module Schemacop
59
59
  end
60
60
 
61
61
  def test_hash
62
- schema { obj! :myobj, String }
62
+ schema do
63
+ obj! :myobj, classes: String
64
+ end
65
+
63
66
  assert_json(
64
67
  type: :object,
65
68
  properties: {
@@ -78,6 +81,16 @@ module Schemacop
78
81
  end
79
82
  end
80
83
 
84
+ def test_hash_no_class
85
+ schema do
86
+ obj! :myobj
87
+ end
88
+
89
+ assert_validation(myobj: 'str')
90
+ assert_validation(myobj: 123)
91
+ assert_validation(myobj: Object.new)
92
+ end
93
+
81
94
  def test_enum_schema
82
95
  schema :object, enum: [true, 'foo', :baz, [], { qux: '123' }]
83
96
 
@@ -70,6 +70,20 @@ module Schemacop
70
70
  error '/', 'Value not included in enum [1, 2, "foo", :bar, {:qux=>42}].'
71
71
  end
72
72
  end
73
+
74
+ # rubocop:disable Lint/BooleanSymbol
75
+ def test_cast_str
76
+ schema :symbol, cast_str: true
77
+
78
+ assert_cast('true', :true)
79
+ assert_cast('foo', :foo)
80
+ assert_cast('1', :'1')
81
+
82
+ assert_cast(:true, :true)
83
+ assert_cast(:foo, :foo)
84
+ assert_cast(:'1', :'1')
85
+ end
86
+ # rubocop:enable Lint/BooleanSymbol
73
87
  end
74
88
  end
75
89
  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.7
4
+ version: 3.0.8
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-02-22 00:00:00.000000000 Z
11
+ date: 2021-02-23 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.1.4
296
- signing_key:
295
+ rubygems_version: 3.1.2
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.