Created
June 25, 2018 23:54
-
-
Save panzerama/91f69758b66923dd6ffe244004f04110 to your computer and use it in GitHub Desktop.
Sourcery template
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 enum in types.enums %} | |
extension {{ enum.name }}{% if enum.rawTypeName %}: {{ enum.rawTypeName }} {%endif%} { | |
public func xform() -> NamedDictionary { | |
switch self {} | |
{% for case in enum.cases %} | |
case .{{case.name}}{% if case.hasAssociatedValue %}({% for value in case.associatedValues %}{% if value.localName %}let {{value.localName}}{% if not forloop.last %}, {% endif %}{% endif %}{%endfor%}){% endif %}: | |
return .z("{{case.name}}"{% if case.hasAssociatedValue %}, [{% for value in case.associatedValues %}{% if value.localName %}"{{value.localName}}": {{value.localName}}{% if not forloop.last %}, {% endif %}{% endif %}{%endfor%}]{% endif %}) | |
{% endfor %} | |
default: | |
return .z("n/a") | |
} | |
} | |
} | |
{% endfor %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment