diff options
author | Brian Waldon <bcwaldon@gmail.com> | 2012-06-01 15:15:48 -0700 |
---|---|---|
committer | Brian Waldon <bcwaldon@gmail.com> | 2012-06-01 15:15:50 -0700 |
commit | c64a586a9a48c8e54e5c702376443767e723fca7 (patch) | |
tree | 7c7ba0adc6a57cc4c038f5ecb96478d153d279cb | |
parent | 96ef8b7a5faa6b8c744e658f33923cb571f50564 (diff) | |
download | warlock-c64a586a9a48c8e54e5c702376443767e723fca7.tar.gz |
Settling on warlock.model_factory
Also making pylint happier
-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 |