README_V3.md in schemacop-3.0.10 vs README_V3.md in schemacop-3.0.11

- old
+ new

@@ -315,11 +315,11 @@ The received number has to be a multiple of the given number for the validation to pass. * `cast_str` When set to `true`, this node also accepts strings that can be casted to an integer, e.g. the values `'-5'` or `'42'`. Please note that you can only validate numbers which - are in the `Integer` format. + are in the `Integer` format. Blank strings will be treated equally as `nil`. #### Examples ```ruby # Validates that the input is an even number between 0 and 100 (inclusive) @@ -344,12 +344,25 @@ schema.validate!('-2') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1. schema.validate!('102') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1. schema.validate!('42.1') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1. schema.validate!('4r') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1. schema.validate!('(4 + 0i)') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1. +schema.validate!(nil) # => nil +schema.validate!('') # => nil ``` +Please note, that `nil` and blank strings are treated equally when using the `cast_str` option, +and validating a blank string will return `nil`. +If you need a value, use the `required` option: + +```ruby +schema = Schemacop::Schema3.new(:integer, minimum: 0, maximum: 100, multiple_of: 2, cast_str: true, required: true) +schema.validate!('42') # => 42 +schema.validate!(nil) # => Schemacop::Exceptions::ValidationError: /: Value must be given. +schema.validate!('') # => Schemacop::Exceptions::ValidationError: /: Value must be given. +``` + ### Number Type: `:number`\ DSL: `num` @@ -384,11 +397,11 @@ pass. * `cast_str` When set to `true`, this node also accepts strings that can be casted to a number, e.g. the values `'0.1'` or `'3.1415'`. Please note that you can only validate numbers which are in the `Integer` or `Float` format, i.e. values like `'1.5r'` or `'(4 + 0i)'` will - not work. + not work. Blank strings will be treated equally as `nil`. #### Examples ```ruby # Validates that the input is a number between 0 and 50 (inclusive) and a multiple of 0.5 @@ -412,23 +425,36 @@ schema.validate!('-2') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1. schema.validate!('51') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1. schema.validate!('42.5') # => 42.5 schema.validate!('1.5r') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1. schema.validate!('(4 + 0i)') # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1. +schema.validate!(nil) # => nil +schema.validate!('') # => nil ``` +Please note, that `nil` and blank strings are treated equally when using the `cast_str` option, +and validating a blank string will return `nil`. +If you need a value, use the `required` option: + +```ruby +schema = Schemacop::Schema3.new(:number, cast_str: true, minimum: 0.0, maximum: (50r), multiple_of: BigDecimal('0.5'), require: true) +schema.validate!('42.5') # => 42.5 +schema.validate!(nil) # => Schemacop::Exceptions::ValidationError: /: Value must be given. +schema.validate!('') # => Schemacop::Exceptions::ValidationError: /: Value must be given. +``` + ### Symbol Type: `:symbol`\ DSL: `sym` The symbol type is used to validate elements for the Ruby `Symbol` class. #### Options * `cast_str` - When set to `true`, this node also accepts strings that can be casted to a symbol. + When set to `true`, this node also accepts strings that can be casted to a symbol. Blank strings will be treated equally as `nil`. #### Examples ```ruby # Validates that the input is a symbol @@ -448,12 +474,25 @@ schema.validate!(':foo') # => :":foo" schema.validate!('foo') # => :foo schema.validate!('123') # => :"123" schema.validate!('false') # => :false schema.validate!(':false') # => :":false" +schema.validate!(nil) # => nil +schema.validate!('') # => nil ``` +Please note, that `nil` and blank strings are treated equally when using the `cast_str` option, +and validating a blank string will return `nil`. +If you need a value, use the `required` option: + +```ruby +schema = Schemacop::Schema3.new(:symbol, cast_str: true, required: true) +schema.validate!('foo') # => :foo +schema.validate!(nil) # => Schemacop::Exceptions::ValidationError: /: Value must be given. +schema.validate!('') # => Schemacop::Exceptions::ValidationError: /: Value must be given. +``` + ### Boolean Type: `:boolean`\ DSL: `boo` @@ -461,11 +500,11 @@ #### Options * `cast_str` When set to `true`, this node also accepts strings that can be casted to a boolean, i.e. - the values `'true'` and `'false'` + the values `'true'` and `'false'`. Blank strings will be treated equally as `nil`. #### Examples ```ruby # Validates that the input is a boolean @@ -484,9 +523,22 @@ schema.validate!(true) # => true schema.validate!(false) # => false schema.validate!(:false) # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1. schema.validate!('false') # => false schema.validate!(1234) # => Schemacop::Exceptions::ValidationError: /: Matches 0 definitions but should match exactly 1. +schema.validate!(nil) # => nil +schema.validate!('') # => nil +``` + +Please note, that `nil` and blank strings are treated equally when using the `cast_str` option, +and validating a blank string will return `nil`. +If you need a value, use the `required` option: + +```ruby +schema = Schemacop::Schema3.new(:boolean, cast_str: true, required: true) +schema.validate!('false') # => false +schema.validate!(nil) # => Schemacop::Exceptions::ValidationError: /: Value must be given. +schema.validate!('') # => Schemacop::Exceptions::ValidationError: /: Value must be given. ``` ### Array Type: `:array`\