diff options
author | Brian Waldon <bcwaldon@gmail.com> | 2012-06-02 12:25:17 -0700 |
---|---|---|
committer | Brian Waldon <bcwaldon@gmail.com> | 2012-06-02 12:25:17 -0700 |
commit | 78cca7b414c45ceaacf621140c5483469e26d03d (patch) | |
tree | b8808e3539c262a6817989aa472d4c91193220cb /README.md | |
parent | f123669b5acfb5c2d134fc6a15e1eee866234ddf (diff) | |
download | warlock-78cca7b414c45ceaacf621140c5483469e26d03d.tar.gz |
Update README.md
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 38 |
1 files changed, 27 insertions, 11 deletions
@@ -1,27 +1,43 @@ # Warlock! -1) Create a class +## Wat - import warlock +Build self-validating python objects using JSON schemas - schema = { +## How + +1) Build your schema + + >>> schema = { 'name': 'Country', 'properties': { 'name': {'type': 'string'}, 'abbreviation': {'type': 'string'}, }, + 'additionalProperties': False, } - Country = warlock.model_factory(schema) +2) Create a model + + >>> import warlock + >>> Country = warlock.model_factory(schema) -2) Create an object using your class +3) Create an object using your model - sweden = Country(name='Sweden', abbreviation='SE') + >>> sweden = Country(name='Sweden', abbreviation='SE') -3) Let the object validate itself! +4) Let the object validate itself! - sweden.name = 5 - # Raises ValueError + >>> sweden.name = 5 + Traceback (most recent call last): + File "<stdin>", line 1, in <module> + File "warlock/core.py", line 53, in __setattr__ + raise InvalidOperation() + warlock.core.InvalidOperation - sweden.overlord = 'Bears' - # Raises AttributeError + >>> sweden.overlord = 'Bears' + Traceback (most recent call last): + File "<stdin>", line 1, in <module> + File "warlock/core.py", line 53, in __setattr__ + raise InvalidOperation() + warlock.core.InvalidOperation
\ No newline at end of file |