README_V3.md in schemacop-3.0.8 vs README_V3.md in schemacop-3.0.9

- old
+ new

@@ -206,10 +206,14 @@ * `format` The `format` option allows for basic semantic validation on certain kinds of string values that are commonly used. See section *formats* for more information on the available formats. Note that strings with a format are also **casted** into that format. +* `allow_blank` + By default, blank strings are allowed and left as they are when casted (e.g. + the string `''` is valid). If you want to disallow blank strings, set this + option to `false`. #### Formats * `date` A date according to [ RFC 3339, section @@ -244,9 +248,41 @@ * `symbol` The string can be anything and will be casted to a ruby `Symbol` object. #### Examples + +```ruby +# Basic example +schema = Schemacop::Schema3.new :string +schema.validate!(nil) # => nil +schema.validate!('') # => "" +schema.validate!('foo') # => "foo" +schema.validate!("\n") # => "\n" +``` + +With the `required` option: + +```ruby +# Basic example +schema = Schemacop::Schema3.new :string, required: true +schema.validate!(nil) # => Schemacop::Exceptions::ValidationError: /: Value must be given. +schema.validate!('') # => "" +schema.validate!('foo') # => "foo" +schema.validate!("\n") # => "\n" +``` + +With the `allow_blank` option: + +```ruby +# Basic example +schema = Schemacop::Schema3.new :string, allow_blank: false +schema.validate!(nil) # => Schemacop::Exceptions::ValidationError: /: String is blank but must not be blank! +schema.validate!('') # => Schemacop::Exceptions::ValidationError: /: String is blank but must not be blank! +schema.validate!('foo') # => "foo" +schema.validate!("\n") # => Schemacop::Exceptions::ValidationError: /: String is blank but must not be blank! +``` +Example of using a `format` option: ```ruby # By using a format, string values are casted to that respective format schema = Schemacop::Schema3.new(:string, format: :date) result = schema.validate('1980-01-13')