Skip to content

Commit

Permalink
docs: api reference
Browse files Browse the repository at this point in the history
  • Loading branch information
Julián Cortés committed Jul 23, 2020
1 parent 4c79d1c commit efdc5fa
Show file tree
Hide file tree
Showing 13 changed files with 506 additions and 310 deletions.
4 changes: 4 additions & 0 deletions docs/api/entity.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Entity
------

.. autoclass:: nyoibo.entities.Entity
58 changes: 58 additions & 0 deletions docs/api/fields.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
.. _fields:

Fields
======

Base Field
----------

.. autoclass:: nyoibo.fields.Field
:members:

String Field
------------

.. autoclass:: nyoibo.fields.StrField
:members:

Integer Field
-------------

.. autoclass:: nyoibo.fields.IntField
:members:

Boolean Field
-------------

.. autoclass:: nyoibo.fields.BoolField
:members:

Date Field
----------

.. autoclass:: nyoibo.fields.DateField
:members:

Datetime Field
--------------

.. autoclass:: nyoibo.fields.DatetimeField
:members:

Float Field
-----------

.. autoclass:: nyoibo.fields.FloatField
:members:

Decimal Field
-------------

.. autoclass:: nyoibo.fields.DecimalField
:members:

Link Field
----------

.. autoclass:: nyoibo.fields.LinkField
:members:
8 changes: 8 additions & 0 deletions docs/api/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
API Reference
=============

.. toctree::
:maxdepth: 2

entity.rst
fields.rst
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ Contents
:maxdepth: 2

usage
api/index
2 changes: 1 addition & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ setter in ``get_{field_name}`` or ``set_{field_name}`` way. Example:
Fields
------

Nyoibo has several fields type (you can check all types in API reference).
Nyoibo has several fields type (you can check all types in :ref:`fields`).
Each field has an internal Python type and it will try to parse and cast to
this Python type. So ``StrField`` will cast to ``str``, ``IntField`` will cast
to ``int``, ``FloatField`` to ``float`` and so on. Let's see an example:
Expand Down
124 changes: 83 additions & 41 deletions nyoibo/entities/entity.c

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions nyoibo/entities/entity.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ from .meta_entity import MetaEntity


class Entity(metaclass=MetaEntity):
"""Entity.
This class must be superclass for classes that you want create getters or
setters.
All fields must starts with ``_``.
Args:
kwargs: values to fields.
Raises:
FieldValueError: if the casting failed.
PrivateFieldError: if a field does not start with ``_``.
This exception is raised when program starts.
"""

def __init__(self, **kwargs):
cdef str key
Expand Down
4 changes: 2 additions & 2 deletions nyoibo/entities/meta_entity.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Dict, Any

from nyoibo.exceptions import PrivateField
from nyoibo.exceptions import PrivateFieldError
from nyoibo.fields import Field


Expand All @@ -25,7 +25,7 @@ def __new__(mcs, name, bases, namespace: Dict[str, Any]):
for attr, value in namespace.items():
if isinstance(value, Field):
if not attr.startswith('_'):
raise PrivateField('Fields must be private')
raise PrivateFieldError('Fields must be private')

fields[attr] = value
MetaEntity._set_getters_and_setters(
Expand Down
2 changes: 1 addition & 1 deletion nyoibo/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class NyoiboError(Exception):
pass


class PrivateField(NyoiboError):
class PrivateFieldError(NyoiboError):
pass


Expand Down
Loading

0 comments on commit efdc5fa

Please sign in to comment.