Created
September 4, 2017 16:49
-
-
Save khanlou/b0d3d3c9dc3551e33db363800a2a368c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% for type in types.implementing.AutoRelationshipable %} | |
extension {{ type.name }} { | |
{% for variable in type.storedVariables %} | |
{% if variable.name|hasSuffix:"ID" and variable.annotations.relationshipType %} | |
var {% if variable.annotations.relationshipName %}{{ variable.annotations.relationshipName }}{% else %}{{ variable.name|replace:"ID","" }}{% endif %}: {{ variable.annotations.relationshipType }}? { | |
{% if variable.isOptional %} | |
guard let {{ variable.name }} = {{ variable.name }} else { return nil } | |
return FlatCache.shared.get(id: {{ variable.name }}) | |
{% else %} | |
return FlatCache.shared.get(id: {{ variable.name }}) | |
{% endif %} | |
} | |
{% elif variable.name|hasSuffix:"IDs" and variable.annotations.relationshipType %} | |
var {% if variable.annotations.relationshipName %}{{ variable.annotations.relationshipName }}{% else %}{{ variable.name|replace:"ID","" }}{% endif %}: [{{ variable.annotations.relationshipType }}] { | |
return {{variable.name}}.flatMap { id -> {{ variable.annotations.relationshipType }}? in | |
return FlatCache.shared.get(id: id) | |
} | |
} | |
{% endif %} | |
{% endfor %} | |
} | |
{% endfor %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment