README_V3.md in schemacop-3.0.15 vs README_V3.md in schemacop-3.0.16
- old
+ new
@@ -19,10 +19,11 @@
11. [OneOf](#oneOf)
12. [IsNot](#isNot)
13. [Reference](#reference)
5. [Context](#context)
6. [External schemas](#external-schemas)
+7. [Default options](#default-options)
## Validation
Using Schemacop, you can either choose to validate your data either using the
graceful `validate` method, or the bang variant, `validate!`.
@@ -337,10 +338,12 @@
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. Blank strings will be treated equally as `nil`.
+ Strings will be parsed with base 10, so only decimal numbers are allowed.
+ Leading zeroes will be ignored.
#### Examples
```ruby
# Validates that the input is an even number between 0 and 100 (inclusive)
@@ -418,11 +421,13 @@
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. Blank strings will be treated equally as `nil`.
+ not work. Blank strings will be treated equally as `nil`. Strings will be
+ parsed with base 10, so only decimal numbers are allowed. Leading zeroes will
+ be ignored.
#### Examples
```ruby
# Validates that the input is a number between 0 and 50 (inclusive) and a multiple of 0.5
@@ -1447,5 +1452,23 @@
```
As mentioned before, you can also use the external schemas without having to
eager-load them, but if you use the schemas multiple times, it might be better
to eager-load them on start of your application / script.
+
+## Default options
+
+Using the setting `Schemacop.v3_default_options`, you can specify a hash
+containing default options that will be used for every schemacop node (options
+not supported by a particular node are automatically ignored). Options passed
+directly to a node still take precedence. The setting can be set in an
+initializer:
+
+```ruby
+# config/initializers/schemacop.rb
+Schemacop.v3_default_options = { cast_str: true }.freeze
+
+# Example schema: As cast_str is enabled in the default options, strings will
+# automatically be casted where supported.
+schema = Schemacop::Schema3.new(:integer)
+schema.validate!('42') # => 42
+```