diff options
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | test/test_core.py | 2 | ||||
-rw-r--r-- | warlock/__init__.py | 5 | ||||
-rw-r--r-- | warlock/core.py | 14 |
4 files changed, 17 insertions, 6 deletions
@@ -12,7 +12,7 @@ }, } - Country = warlock.Class(schema) + Country = warlock.model_factory(schema) 2) Create an object using your class diff --git a/test/test_core.py b/test/test_core.py index a59778c..1aced02 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -13,7 +13,7 @@ class TestCore(unittest.TestCase): }, } - Country = warlock.Class(schema) + Country = warlock.model_factory(schema) sweden = Country(name='Sweden', abbreviation='SE') diff --git a/warlock/__init__.py b/warlock/__init__.py index 2bdde37..f9c0313 100644 --- a/warlock/__init__.py +++ b/warlock/__init__.py @@ -1 +1,4 @@ -from core import Class +"""Public-facing Warlock API""" + +# pylint: disable=W0611 +from warlock.core import model_factory diff --git a/warlock/core.py b/warlock/core.py index 741d137..1753d24 100644 --- a/warlock/core.py +++ b/warlock/core.py @@ -1,8 +1,15 @@ +"""Core Warlock functionality""" + #import jsonschema -def Class(schema): - class schema_class(object): +def model_factory(schema): + """Generate a model class based on the provided JSON Schema + + :param schema: dict representing valid JSON schema + """ + class Model(object): + """Self-validating model for arbitrary objects""" def __init__(self, **kwargs): self.__dict__['raw'] = kwargs @@ -18,4 +25,5 @@ def Class(schema): else: raise AttributeError(key) - return schema_class + Model.__name__ = schema['name'] + return Model |