Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import WeatherCore
- {# define placeholder #}
- {% macro placeholder param_argument %}
- {% if param_argument.type.name|replace:"?","" == "String" %}""
- {% elif param_argument.typeName|replace:"Int","Integer" == "Integer" %}0
- {% elif param_argument.isArray %}
- {% for arrayModel in types.all|struct where arrayModel.name == param_argument.typeName|replace:"[",""|replace:"]","" %}
- {% for childArrayRealmModel in arrayModel.allVariables where childArrayRealmModel.name == "object" %}
- {% for childClass in types.all|class where childClass.name == childArrayRealmModel.typeName|replace:".Type","" %}
- {% for childObjectVariable in objectClass.allVariables where childObjectVariable.typeName|contains:"List"|contains:"" %}
- {{childObjectVariable.name}}: {{childObjectVariable.typeName}}
- {% endfor %}
- {% endfor %}
- {% endfor %}
- {% endfor %}
- {% elif param_argument.isDictionary %}[:]
- {% elif param_argument.typeName|replace:"Double","Double2" == "Double2" %}0
- {% elif param_argument.typeName|replace:"?","" == "Data" %}Data()
- {% elif argument.typeName|replace:"?","" == "Date" %}Date(){% endif %}
- {% endmacro %}
- {% for domainModel in types.implementing.AutoObjectInit|struct where domainModel.accessLevel == "public" %}
- {% for realmModel in domainModel.allVariables where realmModel.name == "object" %}
- {% for objectClass in types.all|class where objectClass.name == realmModel.typeName|replace:".Type","" %}
- public extension {{ domainModel.name }} {
- public static func new(object: {{ objectClass.name }}) -> {{ domainModel.name }} {
- return {{domainModel.name}}.new(
- {% for argument in domainModel.variables where not argument.isComputed %}
- {{argument.name}}: {% for objectVariable in objectClass.variables where objectVariable.name == argument.name %}{% if argument.typeName|replace:"Int","Integer" == "Integer" and objectVariable.typeName|replace:"RealmOptional<Int>","RealmOptional<Integer>" == "RealmOptional<Integer>" %}object.{{argument.name}}.value{% elif argument.typeName|replace:"Double","Double2" == "Double2" and objectVariable.typeName|replace:"RealmOptional<Double>","RealmOptional<Double2>" == "RealmOptional<Double2>" %}object.{{argument.name}}.value ?? 0{% elif argument.type.kind == "struct" %}{% for childRealmModel in argument.type.allVariables where childRealmModel.name == "object" %}{% for childRealmModel in argument.type.allVariables where childRealmModel.name == "object" %}{% for childClass in types.all|class where childClass.name == childRealmModel.typeName|replace:".Type","" %}{% for childObjectVariable in objectClass.allVariables where childObjectVariable.type.name == childClass.name %}{{argument.typeName}}.new(object: object.{{ childObjectVariable.name}}{% ifnot argument.isOptional %}!{% endif %}){% endfor %}{% endfor %}{% endfor %}{% endfor %}{% elif argument.typeName|replace:"Double?","Double2?" == "Double2?" and objectVariable.typeName|replace:"RealmOptional<Double>","RealmOptional<Double2>" == "RealmOptional<Double2>" %}object.{{argument.name}}.value{% elif objectVariable.type.name != argument.type.name %}{% call placeholder argument %}{% else %}object.{{argument.name}}{% if objectVariable.isOptional %}{% ifnot argument.isOptional %} ?? {% call placeholder argument %}{% endif %}{% endif %}{% endif %}{% empty %}{% call placeholder argument %}{% endfor %}{% if not forloop.last %}, {% endif %}{% endfor %}
- )
- {% endfor %}
- {% endfor %}
- }
- }
- {% endfor %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement