Skip to content

Commit

Permalink
Update documentation for pyeve#268 and rule_filter
Browse files Browse the repository at this point in the history
  • Loading branch information
dkellner committed Sep 28, 2016
1 parent eeab863 commit 494085b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
26 changes: 26 additions & 0 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,32 @@ mapping that is checked against the :ref:`schema <schema_dict-rule>` rule:
.. versionchanged:: 0.8
``allow_unknown`` can also be set to a validation schema.

Filter rules
------------
You can filter the rules to be processed by a ``Validator``-instance by
providing a function returning either ``True`` or ``False`` given a rule name.

.. doctest::

>>> schema = {'name': {'type': 'string', 'maxlength': 10}}
>>> v.rule_filter = lambda f: f != 'maxlength'
>>> v.validate({'name': 'Johanna-Maria'}, schema)
True

Regardless of the ``rule_filter``, the ``Validator`` always recurses down
subdocuments:

.. doctest::

>>> schema = {'entries': {'type': 'list', 'schema': {'type': 'integer', 'max': 10}}}
>>> v.rule_filter = lambda f: f == 'type'
>>> v.validate({'entries': [10, 20, 30]}, schema)
True

>>> schema = {'entries': {'type': 'list', 'schema': {'type': 'integer', 'max': 10}}}
>>> v.rule_filter = lambda f: f in ('type', 'max')
>>> v.validate({'entries': [10, 20, 30]}, schema)
False

Fetching Processed Documents
----------------------------
Expand Down
5 changes: 4 additions & 1 deletion docs/validation-rules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,10 @@ readonly
If ``True`` the value is readonly. Validation will fail if this field is
present in the target dictionary. This is useful, for example, when receiving
a payload which is to be validated before it is sent to the datastore. The field
might be provided by the datastore, but should not writable.
might be provided by the datastore, but should not be writable.

``readonly`` can be combined with ``default`` because validation of
``readonly`` is done before normalization.

regex
-----
Expand Down

0 comments on commit 494085b

Please sign in to comment.