Skip to content

Commit

Permalink
Updated docs (closes jazzband#48).
Browse files Browse the repository at this point in the history
  • Loading branch information
beregond committed Nov 12, 2014
1 parent 83ebf97 commit 3240141
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 34 deletions.
26 changes: 11 additions & 15 deletions CONTRIBUTING.rst
Expand Up @@ -3,7 +3,7 @@ Contributing
============

Contributions are welcome, and they are greatly appreciated! Every
little bit helps, and credit will always be given.
little bit helps, and credit will always be given.

You can contribute in many ways:

Expand Down Expand Up @@ -36,15 +36,14 @@ is open to whoever wants to implement it.
Write Documentation
~~~~~~~~~~~~~~~~~~~

JSON models could always use more documentation, whether as part of the
JSON models could always use more documentation, whether as part of the
official JSON models docs, in docstrings, or even on the web in blog posts,
articles, and such.

Submit Feedback
~~~~~~~~~~~~~~~

The best way to send feedback is to file an issue at
https://github.com/beregond/jsonmodels/issues.
The best way to send feedback is to file an issue at https://github.com/beregond/jsonmodels/issues.

If you are proposing a feature:

Expand Down Expand Up @@ -77,8 +76,7 @@ Ready to contribute? Here's how to set up `jsonmodels` for local development.

Now you can make your changes locally.

5. When you're done making changes, check that your changes pass the tests,
including testing other Python versions with tox::
5. When you're done making changes, check that your changes pass the tests, including testing other Python versions with tox::

$ python setup.py test
$ tox
Expand All @@ -99,18 +97,16 @@ Pull Request Guidelines
Before you submit a pull request, check that it meets these guidelines:

1. The pull request should include tests.

2. If the pull request adds functionality, the docs should be updated. Put your
new functionality into a function and add the histry entry using
`pyhistory`.

3. The pull request should work for Python 2.6, 2.7, and 3.4, and for PyPy.
Check https://travis-ci.org/beregond/jsonmodels/pull_requests and make sure
that the tests pass for all supported Python versions.
2. If the pull request adds functionality, the docs should be updated. Put
your new functionality into a function with a docstring, and add the
feature to the list in README.rst.
3. The pull request should work for Python 2.6, 2.7, and 3.4, and for PyPy. Check
https://travis-ci.org/beregond/jsonmodels/pull_requests
and make sure that the tests pass for all supported Python versions.

Tips
----

To run a subset of tests::

$ py.test -k test_jsonmodels
$ python -m unittest tests.test_jsonmodels
10 changes: 5 additions & 5 deletions README.rst
Expand Up @@ -31,7 +31,7 @@ Features

.. code-block:: python
from jsonmodels import models, fields, errors, validators
from jsonmodels import models, fields, error, validators
class Cat(models.Base):
Expand Down Expand Up @@ -226,11 +226,11 @@ Features
.. code-block:: python
>>> from jsonmodels.utils import compare_schemas
>>> first = {'type': 'object'}
>>> second = {'type': 'list'}
>>> compare_schemas(first, first)
>>> schema1 = {'type': 'object'}
>>> schema2 = {'type': 'list'}
>>> compare_schemas(schema1, schema1)
True
>>> compare_schemas(first, second)
>>> compare_schemas(schema1, schema2)
False
More
Expand Down
28 changes: 14 additions & 14 deletions docs/usage.rst
Expand Up @@ -12,9 +12,10 @@ Creating models
---------------

To create models you need to create class that inherits from
:class:`jsonmodels.models.Base` and have class attributes which values inherits
from :class:`jsonmodels.fields.BaseField` (so all other fields classes from
:mod:`jsonmodels.fields`).
:class:`jsonmodels.models.Base` (and *NOT* :class:`jsonmodels.models.PreBase`
to which although refers links in documentation) and have class attributes
which values inherits from :class:`jsonmodels.fields.BaseField` (so all other
fields classes from :mod:`jsonmodels.fields`).

.. code-block:: python
Expand Down Expand Up @@ -48,7 +49,7 @@ Usage
-----

After that you can use it as normal object. You can pass kwargs in constructor
or :meth:`jsonmodels.models.Base.populate` method.
or :meth:`jsonmodels.models.PreBase.populate` method.

.. code-block:: python
Expand All @@ -67,8 +68,8 @@ Validation
----------

You can specify which fields are *required*, if required value is absent during
:meth:`jsonmodels.models.Base.validate` the
:class:`jsonmodels.errors.ValidationError` will be raised.
:meth:`jsonmodels.models.PreBase.validate` the
:class:`jsonmodels.error.ValidationError` will be raised.

.. code-block:: python
Expand All @@ -79,7 +80,6 @@ You can specify which fields are *required*, if required value is absent during
>>> dafty.validate()
*** ValidationError: Field "name" is required!
Validators
~~~~~~~~~~

Expand All @@ -97,28 +97,28 @@ Custom validators
You can always specify your own validators. Custom validator can be object with
`validate` method (which takes precedence) or function (or callable object).

Each validator **must** raise exception to indicate validation didn't pass.
Returning values like `False` won't have any effect.
Each validator **must** raise exception to indicate validation
didn't pass. Returning values like `False` won't have any effect.

.. code-block:: python
>>> class RangeValidator(object):
...
... def __init__(self, min, max):
... # Some logic here.
... # Some logic here.
...
... def validate(self, value):
... # Some logic here.
... # Some logic here.
>>> def some_validator(value):
... # Some logic here.
... # Some logic here.
>>> class Person(models.Base):
...
... name = fields.StringField(required=True, validators=some_validator)
... surname = fields.StringField(required=True)
... age = fields.IntField(
... Car, validators=[some_validator, RangeValidator(0, 100)])
... Car, validators=[some_validator, RangeValidator(0, 100)])
If your validator have method `modify_schema` you can use it to affect
generated schema in any way. Given argument is schema for single field. For
Expand All @@ -142,7 +142,7 @@ Casting to Python struct (and JSON)
-----------------------------------

Instance of model can be easy casted to Python struct (and thanks to that,
later to JSON). See :meth:`jsonmodels.models.Base.to_struct`.
later to JSON). See :meth:`jsonmodels.models.PreBase.to_struct`.

.. code-block:: python
Expand Down

0 comments on commit 3240141

Please sign in to comment.