/* DO NOT EDIT | Generated by gyro */
import ObjectMapper
extension {{ entity.name }}: Mappable {
// MARK: Initializers convenience init?(map: Map) { self.init() } // MARK: Mappable func mapping(map: Map) { {%- if entity.attributes.size > 0 %} // MARK: Attributes {%- endif -%} {%- for attribute in entity.attributes -%} {% assign attributeKey = attribute.name -%} {%- if attribute.json_key_path.size > 0 -%} {%- assign attributeKey = attribute.json_key_path -%} {%- endif -%} {%- case attribute.type -%} {%- when "date" -%} {%- assign transformer = "ISO8601DateTransform" -%} {%- if attribute.transformer.size > 0 -%} {%- assign transformer = attribute.transformer -%} {%- endif %} self.{{ attribute.name }} <- (map["{{ attributeKey }}"], {{ transformer }}()) {%- when "integer_16" or "integer_32" or "integer_64" or "float" or "double" or "boolean" -%} {%- if attribute.optional == true and attribute.enum_type.size == 0 %} self.{{ attribute.name }}.value <- map["{{ attributeKey }}"] {%- else %} {%- if attribute.transformer.size > 0 %} self.{{ attribute.name }} <- (map["{{ attributeKey }}"], {{ attribute.transformer }}()) {%- else %} self.{{ attribute.name }} <- map["{{ attributeKey }}"] {%- endif %} {%- endif -%} {%- else %} {%- if attribute.transformer.size > 0 %} self.{{ attribute.name }} <- (map["{{ attributeKey }}"], {{ attribute.transformer }}()) {%- else %} self.{{ attribute.name }} <- map["{{ attributeKey }}"] {%- endif %} {%- endcase -%} {%- endfor -%} {%- if entity.relationships.size > 0 %} // MARK: Relationships {%- endif -%} {%- for relationship in entity.relationships -%} {%- if relationship.inverse == false -%} {% assign relationKey = relationship.name -%} {%- if relationship.json_key_path.size > 0 -%} {%- assign relationKey = relationship.json_key_path -%} {%- endif -%} {%- if relationship.type == "to_many" %} self.{{ relationship.name }} <- (map["{{ relationKey }}"], ListTransform<{{ relationship.inverse_type }}>()) {%- else %} self.{{ relationship.name }} <- map["{{ relationKey }}"] {%- endif -%} {%- endif -%} {%- endfor %} }
}