Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
{% 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