|
| 1 | + |
| 2 | +""" |
| 3 | +Specification definitions in the 'example' namespace. |
| 4 | +
|
| 5 | +Test specifications. |
| 6 | +""" |
| 7 | + |
| 8 | +# WARNING: This file is auto-generated by openassetio-traitgen, do not edit. |
| 9 | + |
| 10 | +from openassetio.trait import TraitsData |
| 11 | + |
| 12 | + |
| 13 | +from .. import traits |
| 14 | + |
| 15 | + |
| 16 | +class ExampleSpecification_v2: |
| 17 | + """ |
| 18 | + An example. |
| 19 | + Usage: entity |
| 20 | + """ |
| 21 | + kTraitSet = { |
| 22 | + # 'openassetio-example:example.Deprecated' |
| 23 | + traits.example.AddedTrait_v1.kId, |
| 24 | + # 'openassetio-example:example.Updated' |
| 25 | + traits.example.UpdatedTrait_v2.kId, |
| 26 | + |
| 27 | + } |
| 28 | + |
| 29 | + def __init__(self, traitsData): |
| 30 | + """ |
| 31 | + Constructs the specification as a view on the supplied |
| 32 | + shared @fqref{TraitsData} "TraitsData" instance. |
| 33 | +
|
| 34 | + @param traitsData @fqref{TraitsData} "TraitsData" |
| 35 | +
|
| 36 | + @warning Specifications are always a view on the supplied data, |
| 37 | + which is held by reference. Any changes made to the data will be |
| 38 | + visible to any other specifications or @ref trait "traits" that |
| 39 | + wrap the same TraitsData instance. |
| 40 | + """ |
| 41 | + if not isinstance(traitsData, TraitsData): |
| 42 | + raise TypeError("Specifications must be constructed with a TraitsData instance") |
| 43 | + self.__data = traitsData |
| 44 | + |
| 45 | + def traitsData(self): |
| 46 | + """ |
| 47 | + Returns the underlying (shared) @fqref{TraitsData} "TraitsData" |
| 48 | + instance held by this specification. |
| 49 | + """ |
| 50 | + return self.__data |
| 51 | + |
| 52 | + @classmethod |
| 53 | + def create(cls): |
| 54 | + """ |
| 55 | + Returns a new instance of the Specification, holding a new |
| 56 | + @fqref{TraitsData} "TraitsData" instance, pre-populated with all |
| 57 | + of the specifications traits. |
| 58 | + """ |
| 59 | + data = TraitsData(cls.kTraitSet) |
| 60 | + return cls(data) |
| 61 | + |
| 62 | + def deprectatedTrait(self): |
| 63 | + """ |
| 64 | + Returns the view for the 'openassetio-example:example.Unchanged' trait wrapped around |
| 65 | + the data held in this instance. |
| 66 | + """ |
| 67 | + return traits.example.DeprecatedTrait_v1(self.traitsData()) |
| 68 | + |
| 69 | + def updatedTrait(self): |
| 70 | + """ |
| 71 | + Returns the view for the 'openassetio-example:example.Updated' trait wrapped around |
| 72 | + the data held in this instance. |
| 73 | + """ |
| 74 | + return traits.example.UpdatedTrait_v2(self.traitsData()) |
| 75 | + |
| 76 | + |
| 77 | +# Alias for latest version. |
| 78 | +ExampleSpecification = ExampleSpecification_v2 |
| 79 | + |
| 80 | + |
| 81 | +class ExampleSpecification_v1: |
| 82 | + """ |
| 83 | + An example. |
| 84 | + Usage: entity |
| 85 | + """ |
| 86 | + kTraitSet = { |
| 87 | + # 'openassetio-example:example.Deprecated' |
| 88 | + traits.example.AddedTrait_v1.kId, |
| 89 | + # 'openassetio-example:example.Updated' |
| 90 | + traits.example.UpdatedTrait_v1.kId, |
| 91 | + |
| 92 | + } |
| 93 | + |
| 94 | + def __init__(self, traitsData): |
| 95 | + """ |
| 96 | + Constructs the specification as a view on the supplied |
| 97 | + shared @fqref{TraitsData} "TraitsData" instance. |
| 98 | +
|
| 99 | + @param traitsData @fqref{TraitsData} "TraitsData" |
| 100 | +
|
| 101 | + @warning Specifications are always a view on the supplied data, |
| 102 | + which is held by reference. Any changes made to the data will be |
| 103 | + visible to any other specifications or @ref trait "traits" that |
| 104 | + wrap the same TraitsData instance. |
| 105 | + """ |
| 106 | + if not isinstance(traitsData, TraitsData): |
| 107 | + raise TypeError("Specifications must be constructed with a TraitsData instance") |
| 108 | + self.__data = traitsData |
| 109 | + |
| 110 | + def traitsData(self): |
| 111 | + """ |
| 112 | + Returns the underlying (shared) @fqref{TraitsData} "TraitsData" |
| 113 | + instance held by this specification. |
| 114 | + """ |
| 115 | + return self.__data |
| 116 | + |
| 117 | + @classmethod |
| 118 | + def create(cls): |
| 119 | + """ |
| 120 | + Returns a new instance of the Specification, holding a new |
| 121 | + @fqref{TraitsData} "TraitsData" instance, pre-populated with all |
| 122 | + of the specifications traits. |
| 123 | + """ |
| 124 | + data = TraitsData(cls.kTraitSet) |
| 125 | + return cls(data) |
| 126 | + |
| 127 | + |
| 128 | + def deprectatedTrait(self): |
| 129 | + """ |
| 130 | + Returns the view for the 'openassetio-example:example.Unchanged' trait wrapped around |
| 131 | + the data held in this instance. |
| 132 | + """ |
| 133 | + return traits.example.DeprecatedTrait_v1(self.traitsData()) |
| 134 | + |
| 135 | + def updatedTrait(self): |
| 136 | + """ |
| 137 | + Returns the view for the 'openassetio-example:example.Updated' trait wrapped around |
| 138 | + the data held in this instance. |
| 139 | + """ |
| 140 | + return traits.example.UpdatedTrait_v1(self.traitsData()) |
0 commit comments