| @@ 45-70 (lines=26) @@ | ||
| 42 | @yorm.attr(falsey=Boolean) |
|
| 43 | @yorm.attr(number_int=Integer) |
|
| 44 | @yorm.attr(number_real=Float) |
|
| 45 | @yorm.attr(object=EmptyDictionary) |
|
| 46 | @yorm.attr(string=String) |
|
| 47 | @yorm.attr(truthy=Boolean) |
|
| 48 | @yorm.sync("tmp/{self.category}/{self.name}.yml") |
|
| 49 | class SampleStandardDecorated: |
|
| 50 | """Sample class using standard attribute types.""" |
|
| 51 | ||
| 52 | def __init__(self, name, category='default'): |
|
| 53 | self.name = name |
|
| 54 | self.category = category |
|
| 55 | # https://docs.python.org/3.4/library/json.html#json.JSONDecoder |
|
| 56 | self.object = {} |
|
| 57 | self.array = [] |
|
| 58 | self.string = "" |
|
| 59 | self.number_int = 0 |
|
| 60 | self.number_real = 0.0 |
|
| 61 | self.truthy = True |
|
| 62 | self.falsey = False |
|
| 63 | self.null = None |
|
| 64 | ||
| 65 | def __repr__(self): |
|
| 66 | return "<decorated {}>".format(id(self)) |
|
| 67 | ||
| 68 | ||
| 69 | @yorm.attr(label=String) |
|
| 70 | @yorm.attr(status=Boolean) |
|
| 71 | class StatusDictionary(Dictionary): |
|
| 72 | """Sample dictionary container.""" |
|
| 73 | ||
| @@ 27-52 (lines=26) @@ | ||
| 24 | @yorm.attr(array=IntegerList) |
|
| 25 | @yorm.attr(false=Boolean) |
|
| 26 | @yorm.attr(number_int=Integer) |
|
| 27 | @yorm.attr(number_real=Float) |
|
| 28 | @yorm.attr(object=EmptyDictionary) |
|
| 29 | @yorm.attr(string=String) |
|
| 30 | @yorm.attr(true=Boolean) |
|
| 31 | @yorm.sync("tmp/path/to/{self.category}/{self.name}.yml") |
|
| 32 | class SampleStandardDecorated: |
|
| 33 | """Sample class using standard attribute types.""" |
|
| 34 | ||
| 35 | def __init__(self, name, category='default'): |
|
| 36 | # pylint: disable=duplicate-code |
|
| 37 | self.name = name |
|
| 38 | self.category = category |
|
| 39 | # https://docs.python.org/3.4/library/json.html#json.JSONDecoder |
|
| 40 | self.object = {} |
|
| 41 | self.array = [] |
|
| 42 | # pylint: disable=duplicate-code |
|
| 43 | self.string = "" |
|
| 44 | self.number_int = 0 |
|
| 45 | self.number_real = 0.0 |
|
| 46 | # pylint: disable=duplicate-code |
|
| 47 | self.true = True |
|
| 48 | self.false = False |
|
| 49 | self.null = None |
|
| 50 | ||
| 51 | def __repr__(self): |
|
| 52 | return "<decorated {}>".format(id(self)) |
|
| 53 | ||
| 54 | ||
| 55 | # TESTS ######################################################################## |
|