gyro 0.4.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +42 -797
- data/bin/gyro +91 -84
- data/documentation/enum.png +0 -0
- data/documentation/enum_json.png +0 -0
- data/documentation/ignored.png +0 -0
- data/documentation/json.png +0 -0
- data/documentation/primary_key.png +0 -0
- data/documentation/read_only.png +0 -0
- data/documentation/simple_entity.png +0 -0
- data/documentation/support_annotation.png +0 -0
- data/documentation/transformer.png +0 -0
- data/documentation/transformers.png +0 -0
- data/lib/gyro.rb +18 -29
- data/lib/gyro/generator/json.rb +30 -0
- data/lib/gyro/generator/liquid.rb +22 -0
- data/lib/gyro/generator/liquid/filters.rb +53 -0
- data/lib/gyro/generator/liquid/liquid.rb +124 -0
- data/lib/gyro/generator/liquid/whitespace_patch.rb +61 -0
- data/lib/gyro/log.rb +46 -0
- data/lib/gyro/parser/xcdatamodel.rb +20 -0
- data/lib/gyro/parser/xcdatamodel/attribute.rb +129 -0
- data/lib/gyro/parser/xcdatamodel/entity.rb +195 -0
- data/lib/gyro/parser/xcdatamodel/relationship.rb +84 -0
- data/lib/gyro/parser/xcdatamodel/xcdatamodel.rb +65 -0
- data/lib/gyro/template.rb +68 -0
- data/lib/gyro/version.rb +19 -0
- data/lib/templates/android/README.md +164 -0
- data/lib/templates/android/entity.liquid +49 -0
- data/lib/templates/android/entity_filename.liquid +1 -0
- data/lib/templates/android/enum.liquid +44 -0
- data/lib/templates/android/enum_filename.liquid +1 -0
- data/lib/templates/android/inc/_attributes_enum.liquid +17 -0
- data/lib/templates/android/inc/_attributes_getter_setter.liquid +58 -0
- data/lib/templates/android/inc/_attributes_properties.liquid +35 -0
- data/lib/templates/android/inc/_enum_getter_setter.liquid +19 -0
- data/lib/templates/android/inc/_primitives.liquid +30 -0
- data/lib/templates/android/inc/_relationships_enum.liquid +14 -0
- data/lib/templates/android/inc/_relationships_getter_setter.liquid +47 -0
- data/lib/templates/android/inc/_relationships_properties.liquid +27 -0
- data/lib/templates/android/inc/_type_converter.liquid +22 -0
- data/lib/templates/android/inc/_wrapper_type_converter.liquid +22 -0
- data/lib/templates/decodable/README.md +34 -0
- data/lib/templates/decodable/entity.liquid +57 -0
- data/lib/templates/decodable/entity_filename.liquid +1 -0
- data/lib/templates/decodable/enum.liquid +0 -0
- data/lib/templates/decodable/enum_filename.liquid +0 -0
- data/lib/templates/object-mapper/README.md +40 -0
- data/lib/templates/object-mapper/entity.liquid +66 -0
- data/lib/templates/object-mapper/entity_filename.liquid +1 -0
- data/lib/templates/object-mapper/enum.liquid +0 -0
- data/lib/templates/object-mapper/enum_filename.liquid +0 -0
- data/lib/templates/swift3-variant/README.md +60 -0
- data/lib/templates/swift3-variant/entity.liquid +12 -0
- data/lib/templates/swift3-variant/entity_filename.liquid +1 -0
- data/lib/templates/swift3-variant/enum.liquid +15 -0
- data/lib/templates/swift3-variant/enum_filename.liquid +1 -0
- data/lib/templates/swift3-variant/inc/_attributes_enum.liquid +13 -0
- data/lib/templates/swift3-variant/inc/_attributes_properties.liquid +32 -0
- data/lib/templates/swift3-variant/inc/_default_value_converter.liquid +14 -0
- data/lib/templates/swift3-variant/inc/_enum_attribute_property.liquid +26 -0
- data/lib/templates/swift3-variant/inc/_ignored_properties.liquid +24 -0
- data/lib/templates/swift3-variant/inc/_indexed_properties.liquid +19 -0
- data/lib/templates/swift3-variant/inc/_inverse_properties.liquid +11 -0
- data/lib/templates/swift3-variant/inc/_optional_attribute_property.liquid +5 -0
- data/lib/templates/swift3-variant/inc/_primary_key.liquid +5 -0
- data/lib/templates/swift3-variant/inc/_relationship_properties.liquid +9 -0
- data/lib/templates/swift3-variant/inc/_relationships_enum.liquid +17 -0
- data/lib/templates/swift3-variant/inc/_type_converter.liquid +20 -0
- data/lib/templates/swift3/README.md +60 -0
- data/lib/templates/swift3/entity.liquid +12 -0
- data/lib/templates/swift3/entity_filename.liquid +1 -0
- data/lib/templates/swift3/enum.liquid +15 -0
- data/lib/templates/swift3/enum_filename.liquid +1 -0
- data/lib/templates/swift3/inc/_attributes_enum.liquid +13 -0
- data/lib/templates/swift3/inc/_attributes_properties.liquid +32 -0
- data/lib/templates/swift3/inc/_default_value_converter.liquid +14 -0
- data/lib/templates/swift3/inc/_enum_attribute_property.liquid +26 -0
- data/lib/templates/swift3/inc/_ignored_properties.liquid +24 -0
- data/lib/templates/swift3/inc/_indexed_properties.liquid +19 -0
- data/lib/templates/swift3/inc/_inverse_properties.liquid +11 -0
- data/lib/templates/swift3/inc/_optional_attribute_property.liquid +5 -0
- data/lib/templates/swift3/inc/_primary_key.liquid +5 -0
- data/lib/templates/swift3/inc/_relationship_properties.liquid +9 -0
- data/lib/templates/swift3/inc/_relationships_enum.liquid +17 -0
- data/lib/templates/swift3/inc/_type_converter.liquid +20 -0
- metadata +134 -31
- data/lib/gyro/realm/java/converter.rb +0 -63
- data/lib/gyro/realm/java/enum_generator.rb +0 -128
- data/lib/gyro/realm/java/generator.rb +0 -183
- data/lib/gyro/realm/java/templates.rb +0 -67
- data/lib/gyro/realm/objc/converter.rb +0 -63
- data/lib/gyro/realm/objc/enum_generator.rb +0 -86
- data/lib/gyro/realm/objc/generator.rb +0 -373
- data/lib/gyro/realm/objc/json_category_generator.rb +0 -172
- data/lib/gyro/realm/objc/protocol_generator.rb +0 -59
- data/lib/gyro/realm/objc/templates.rb +0 -100
- data/lib/gyro/realm/swift/converter.rb +0 -74
- data/lib/gyro/realm/swift/enum_generator.rb +0 -73
- data/lib/gyro/realm/swift/generator.rb +0 -265
- data/lib/gyro/realm/swift/object_mapper_generator.rb +0 -124
- data/lib/gyro/realm/swift/templates.rb +0 -64
- data/lib/gyro/utils/file_utils.rb +0 -31
- data/lib/gyro/utils/log.rb +0 -68
- data/lib/gyro/utils/raise.rb +0 -23
- data/lib/gyro/utils/string_xcdatamodel.rb +0 -58
- data/lib/gyro/xcdatamodel/parser/attribute.rb +0 -98
- data/lib/gyro/xcdatamodel/parser/entity.rb +0 -234
- data/lib/gyro/xcdatamodel/parser/relationship.rb +0 -70
- data/lib/gyro/xcdatamodel/parser/xcdatamodel.rb +0 -59
@@ -0,0 +1 @@
|
|
1
|
+
{{params.prefix}}{{name}}.java
|
@@ -0,0 +1,44 @@
|
|
1
|
+
{%- if attribute.enum_type.size > 0 -%}
|
2
|
+
|
3
|
+
{%- if params.package.size > 0 -%}
|
4
|
+
package {{ params.package }};
|
5
|
+
{%- endif %}
|
6
|
+
|
7
|
+
/* DO NOT EDIT | Generated by gyro */
|
8
|
+
|
9
|
+
public enum {{ attribute.enum_type }} {
|
10
|
+
{% for value in attribute.enum_values %}
|
11
|
+
{% if attribute.enum_values.size > 0 %}
|
12
|
+
{%- assign jsonKey = value -%}
|
13
|
+
{%- if attribute.json_values.size > 0 and attribute.json_values[forloop.index0] -%}
|
14
|
+
{%- assign jsonKey = attribute.json_values[forloop.index0] -%}
|
15
|
+
{%- endif -%}
|
16
|
+
{{ value | snake_case | upcase | strip }}("{{ jsonKey }}")
|
17
|
+
{%- if forloop.last == true -%};{%- else -%},{%- endif -%}
|
18
|
+
{%- endif -%}
|
19
|
+
{%- endfor %}
|
20
|
+
|
21
|
+
private final String jsonValue;
|
22
|
+
|
23
|
+
{{ attribute.enum_type }}(final String jsonValue) {
|
24
|
+
this.jsonValue = jsonValue;
|
25
|
+
}
|
26
|
+
{% if params.support_annotations.size > 0 %}
|
27
|
+
@android.support.annotation.Nullable
|
28
|
+
{%- endif %}
|
29
|
+
public static {{ attribute.enum_type }} get(final String jsonValue) {
|
30
|
+
for (final {{ attribute.enum_type }} type : {{ attribute.enum_type }}.values()) {
|
31
|
+
if (type.getJsonValue().equals(jsonValue)) {
|
32
|
+
return type;
|
33
|
+
}
|
34
|
+
}
|
35
|
+
return null;
|
36
|
+
}
|
37
|
+
{% if params.support_annotations.size > 0 %}
|
38
|
+
@android.support.annotation.NonNull
|
39
|
+
{%- endif %}
|
40
|
+
public String getJsonValue() {
|
41
|
+
return jsonValue;
|
42
|
+
}
|
43
|
+
}
|
44
|
+
{%- endif %}
|
@@ -0,0 +1 @@
|
|
1
|
+
{{params.prefix}}{{name}}.java
|
@@ -0,0 +1,17 @@
|
|
1
|
+
{%- if entity.attributes.size > 0 %}
|
2
|
+
|
3
|
+
public static final class Attributes {
|
4
|
+
{%- for attribute in entity.attributes -%}
|
5
|
+
{%- if attribute.realm_ignored == false or attribute.read_only == false -%}
|
6
|
+
{%- if attribute.comment.size > 0 %}
|
7
|
+
// {{ attribute.comment }}
|
8
|
+
{%- endif %}
|
9
|
+
public static final String {{ attribute.name | snake_case | upcase }} = "{{ attribute.name }}";
|
10
|
+
{%- endif -%}
|
11
|
+
{%- endfor %}
|
12
|
+
|
13
|
+
private Attributes() {
|
14
|
+
// Hide constructor
|
15
|
+
}
|
16
|
+
}
|
17
|
+
{%- endif -%}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
{%- for attribute in entity.attributes %}
|
2
|
+
|
3
|
+
{%- if attribute.realm_read_only.size == 0 %}
|
4
|
+
{%- comment %} ******* CONVERT TYPE CAPTURE ******* {% endcomment -%}
|
5
|
+
|
6
|
+
{%- capture visibility %}
|
7
|
+
{%- if attribute.enum_type.size > 0 and params.hide_members_with_enum.size > 0 -%}
|
8
|
+
protected
|
9
|
+
{%- else -%}
|
10
|
+
public
|
11
|
+
{%- endif %}
|
12
|
+
{%- endcapture %}
|
13
|
+
|
14
|
+
{%- capture convert_type %}
|
15
|
+
{%- if attribute.realm_read_only.size == 0 and attribute.enum_type.size > 0 -%}
|
16
|
+
String
|
17
|
+
{%- else -%}
|
18
|
+
{%- if params.use_wrappers.size > 0 and attribute.optional == true -%}
|
19
|
+
{%- include 'inc/wrapper_type_converter' -%}
|
20
|
+
{%- else -%}
|
21
|
+
{%- include 'inc/type_converter' -%}
|
22
|
+
{%- endif %}
|
23
|
+
{%- endif %}
|
24
|
+
{%- endcapture %}
|
25
|
+
|
26
|
+
{%- capture isPrimitives %}
|
27
|
+
{%- include 'inc/primitives' %}
|
28
|
+
{%- endcapture %}
|
29
|
+
|
30
|
+
{%- capture annotation %}
|
31
|
+
{%- if params.support_annotations.size > 0 %}
|
32
|
+
{%- if isPrimitives == "false" -%}
|
33
|
+
{%- if params.use_wrappers.size > 0 or attribute.enum_type.size > 0 or isPrimitives == "false" -%}
|
34
|
+
@android.support.annotation.{% if attribute.optional == true %}Nullable{% else %}NonNull{%- endif -%}
|
35
|
+
{%- if attribute.support_annotation.size > 0 %}|{%- endif -%}
|
36
|
+
{%- endif -%}
|
37
|
+
{%- endif -%}
|
38
|
+
{%- if attribute.support_annotation.size > 0 -%}
|
39
|
+
@android.support.annotation.{{ attribute.support_annotation }}
|
40
|
+
{%- endif %}
|
41
|
+
{%- endif %}
|
42
|
+
{%- endcapture %}
|
43
|
+
{%- assign name = attribute.name %}
|
44
|
+
{{ empty_line }}
|
45
|
+
|
46
|
+
{%- if annotation.size > 0 %}
|
47
|
+
{{ annotation | replace: "|","
|
48
|
+
" }}
|
49
|
+
{%- endif %}
|
50
|
+
{{ visibility }} {{ convert_type }} get{{ name | titleize }}() {
|
51
|
+
return {{ name }};
|
52
|
+
}
|
53
|
+
|
54
|
+
{{ visibility }} void set{{ name | titleize }}({%- if annotation.size > 0 %}{{ annotation | replace: "|"," " }} {% endif %}final {{ convert_type }} {{ name }}) {
|
55
|
+
this.{{ name }} = {{ name }};
|
56
|
+
}
|
57
|
+
{%- endif %}
|
58
|
+
{%- endfor %}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
|
2
|
+
{%- for attribute in entity.attributes -%}
|
3
|
+
{%- if attribute.realm_read_only.size == 0 -%}
|
4
|
+
{%- comment %} ******* CONVERT TYPE CAPTURE ******* {% endcomment -%}
|
5
|
+
{%- capture convert_type -%}
|
6
|
+
{%- if attribute.realm_read_only.size == 0 and attribute.enum_type.size > 0 -%}
|
7
|
+
String
|
8
|
+
{%- else -%}
|
9
|
+
{%- if params.use_wrappers == "true" and attribute.optional == true -%}
|
10
|
+
{%- include 'inc/wrapper_type_converter' -%}
|
11
|
+
{%- else -%}
|
12
|
+
{%- include 'inc/type_converter' -%}
|
13
|
+
{%- endif -%}
|
14
|
+
{%- endif -%}
|
15
|
+
{%- endcapture -%}
|
16
|
+
|
17
|
+
{%- assign name = attribute.name -%}
|
18
|
+
{%- if name == primary_key %}
|
19
|
+
@PrimaryKey
|
20
|
+
{%- endif -%}
|
21
|
+
{%- if attribute.indexed == true %}
|
22
|
+
@Index
|
23
|
+
{%- endif -%}
|
24
|
+
{%- if attribute.realm_ignored == true %}
|
25
|
+
@Ignore
|
26
|
+
{%- endif -%}
|
27
|
+
{%- if attribute.json_key_path.size > 0 %}
|
28
|
+
@SerializedName("{{ attribute.json_key_path }}")
|
29
|
+
{%- endif -%}
|
30
|
+
{%- if params.support_annotations.size > 0 and attribute.support_annotation.size > 0 %}
|
31
|
+
@android.support.annotation.{{ attribute.support_annotation }}
|
32
|
+
{%- endif %}
|
33
|
+
private {{ convert_type }} {{ name }};
|
34
|
+
{%- endif -%}
|
35
|
+
{%- endfor -%}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
{%- for attribute in entity.attributes %}
|
2
|
+
|
3
|
+
{%- if attribute.realm_read_only.size == 0 and attribute.enum_type.size > 0 %}
|
4
|
+
{% if params.support_annotations.size > 0 %}
|
5
|
+
@android.support.annotation.Nullable
|
6
|
+
{%- capture annotation -%}@android.support.annotation.NonNull {% endcapture -%}
|
7
|
+
{%- endif -%}
|
8
|
+
|
9
|
+
{%- assign name = attribute.name %}
|
10
|
+
public {{ attribute.enum_type }} get{{ name | titleize }}Enum() {
|
11
|
+
return {{ attribute.enum_type }}.get(get{{ name | titleize }}());
|
12
|
+
}
|
13
|
+
|
14
|
+
public void set{{ name | titleize }}Enum({{ annotation }}final {{ attribute.enum_type }} {{ name }}) {
|
15
|
+
this.{{ name }} = {{ name }}.getJsonValue();
|
16
|
+
}
|
17
|
+
{%- endif -%}
|
18
|
+
|
19
|
+
{%- endfor -%}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
{%- capture convert_type %}
|
2
|
+
{%- if attribute.realm_read_only.size == 0 and attribute.enum_type.size > 0 -%}
|
3
|
+
String
|
4
|
+
{%- else -%}
|
5
|
+
{%- if params.use_wrappers.size > 0 and attribute.optional == true -%}
|
6
|
+
{%- include 'inc/wrapper_type_converter' -%}
|
7
|
+
{%- else -%}
|
8
|
+
{%- include 'inc/type_converter' -%}
|
9
|
+
{%- endif %}
|
10
|
+
{%- endif %}
|
11
|
+
{%- endcapture %}
|
12
|
+
|
13
|
+
{%- case convert_type -%}
|
14
|
+
{%- when 'integer_16' or 'short' -%}
|
15
|
+
true
|
16
|
+
{%- when 'integer_32' or 'int' -%}
|
17
|
+
true
|
18
|
+
{%- when 'integer_64' or 'long' -%}
|
19
|
+
true
|
20
|
+
{%- when 'double' or 'decimal' -%}
|
21
|
+
true
|
22
|
+
{%- when 'float' -%}
|
23
|
+
true
|
24
|
+
{%- when 'boolean' -%}
|
25
|
+
true
|
26
|
+
{%- when 'binary' -%}
|
27
|
+
true
|
28
|
+
{%- else -%}
|
29
|
+
false
|
30
|
+
{%- endcase -%}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
{%- if entity.relationships.size > 0 and entity.has_only_inverse == false %}
|
2
|
+
|
3
|
+
public static final class Relationships {
|
4
|
+
{%- for relationship in entity.relationships -%}
|
5
|
+
{%- if relationship.inverse == false %}
|
6
|
+
public static final String {{ relationship.name | snake_case | upcase }} = "{{ relationship.name }}";
|
7
|
+
{%- endif -%}
|
8
|
+
{%- endfor %}
|
9
|
+
|
10
|
+
private Relationships() {
|
11
|
+
// Hide constructor
|
12
|
+
}
|
13
|
+
}
|
14
|
+
{%- endif -%}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
{%- for relationship in entity.relationships %}
|
2
|
+
{%- if relationship.inverse == false %}
|
3
|
+
{%- capture relationship_type %}
|
4
|
+
{%- if relationship.realm_read_only.size == 0 and relationship.enum_type.size > 0 -%}
|
5
|
+
String
|
6
|
+
{%- else %}
|
7
|
+
{%- if relationship.destination.size == 0 %}
|
8
|
+
{%- if relationship.type != "to_many" -%}
|
9
|
+
{{ relationship.inverse_type }}
|
10
|
+
{%- else -%}
|
11
|
+
RealmList<{{ relationship.inverse_type }}>
|
12
|
+
{%- endif %}
|
13
|
+
{%- else -%}
|
14
|
+
List<{{ relationship.destination }}>
|
15
|
+
{%- endif %}
|
16
|
+
{%- endif %}
|
17
|
+
{%- endcapture %}
|
18
|
+
|
19
|
+
{%- capture annotation %}
|
20
|
+
{%- if params.support_annotations.size > 0 %}
|
21
|
+
{%- if relationship.optional == true -%}
|
22
|
+
@android.support.annotation.Nullable
|
23
|
+
{%- endif %}
|
24
|
+
{%- if relationship.optional == false -%}
|
25
|
+
@android.support.annotation.NonNull
|
26
|
+
{%- endif %}
|
27
|
+
{%- if relationship.support_annotation.size > 0 -%}
|
28
|
+
|@android.support.annotation.{{ relationship.support_annotation }}
|
29
|
+
{%- endif %}
|
30
|
+
{%- endif %}
|
31
|
+
{%- endcapture %}
|
32
|
+
|
33
|
+
{%- assign name = relationship.name %}
|
34
|
+
{% comment %} *** Empty line *** {% endcomment %}
|
35
|
+
{%- if annotation.size > 0 %}
|
36
|
+
{{ annotation | replace: "|","
|
37
|
+
" }}
|
38
|
+
{%- endif %}
|
39
|
+
public {{ relationship_type }} get{{ name | titleize }}() {
|
40
|
+
return {{ name }};
|
41
|
+
}
|
42
|
+
|
43
|
+
public void set{{ name | titleize }}({%- if annotation.size > 0 %}{{ annotation | replace: "|"," " }} {% endif %}final {{ relationship_type }} {{ name }}) {
|
44
|
+
this.{{ name }} = {{ name }};
|
45
|
+
}
|
46
|
+
{%- endif %}
|
47
|
+
{%- endfor %}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
{%- for relationship in entity.relationships -%}
|
2
|
+
{%- capture relationship_type -%}
|
3
|
+
{%- if relationship.realm_read_only.size == 0 and relationship.enum_type.size > 0 -%}
|
4
|
+
String
|
5
|
+
{%- else -%}
|
6
|
+
{%- if relationship.destination.size == 0 -%}
|
7
|
+
{%- if relationship.type != "to_many" -%}
|
8
|
+
{{ relationship.inverse_type }}
|
9
|
+
{%- else -%}
|
10
|
+
RealmList<{{ relationship.inverse_type }}>
|
11
|
+
{%- endif -%}
|
12
|
+
{%- else -%}
|
13
|
+
List<{{ relationship.destination }}>
|
14
|
+
{%- endif -%}
|
15
|
+
{%- endif -%}
|
16
|
+
{%- endcapture -%}
|
17
|
+
|
18
|
+
{%- if relationship.inverse == false -%}
|
19
|
+
{%- if relationship.realm_ignored == true %}
|
20
|
+
@Ignore
|
21
|
+
{%- endif -%}
|
22
|
+
{%- if relationship.json_key_path.size > 0 %}
|
23
|
+
@SerializedName("{{ relationship.json_key_path }}")
|
24
|
+
{%- endif %}
|
25
|
+
private {{ relationship_type }} {{ relationship.name }};
|
26
|
+
{%- endif -%}
|
27
|
+
{%- endfor -%}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
{%- case attribute.type -%}
|
2
|
+
{%- when 'integer_16' -%}
|
3
|
+
short
|
4
|
+
{%- when 'integer_32' -%}
|
5
|
+
int
|
6
|
+
{%- when 'integer_64' -%}
|
7
|
+
long
|
8
|
+
{%- when 'double' or 'decimal' -%}
|
9
|
+
double
|
10
|
+
{%- when 'float' -%}
|
11
|
+
float
|
12
|
+
{%- when 'string' -%}
|
13
|
+
String
|
14
|
+
{%- when 'boolean' -%}
|
15
|
+
boolean
|
16
|
+
{%- when 'date' -%}
|
17
|
+
Date
|
18
|
+
{%- when 'binary' -%}
|
19
|
+
byte[]
|
20
|
+
{%- else -%}
|
21
|
+
String
|
22
|
+
{%- endcase -%}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
{%- case attribute.type -%}
|
2
|
+
{%- when 'integer_16' -%}
|
3
|
+
Short
|
4
|
+
{%- when 'integer_32' -%}
|
5
|
+
Integer
|
6
|
+
{%- when 'integer_64' -%}
|
7
|
+
Long
|
8
|
+
{%- when 'double' or 'decimal' -%}
|
9
|
+
Double
|
10
|
+
{%- when 'float' -%}
|
11
|
+
Float
|
12
|
+
{%- when 'string' -%}
|
13
|
+
String
|
14
|
+
{%- when 'boolean' -%}
|
15
|
+
Boolean
|
16
|
+
{%- when 'date' -%}
|
17
|
+
Date
|
18
|
+
{%- when 'binary' -%}
|
19
|
+
Byte[]
|
20
|
+
{%- else -%}
|
21
|
+
String
|
22
|
+
{%- endcase -%}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Decodable Template Information
|
2
|
+
|
3
|
+
| Name | Description |
|
4
|
+
| --------- | ----------------- |
|
5
|
+
| Folder name | templates/decodable |
|
6
|
+
| Invocation example | `gyro -m <model> -t decodable …` |
|
7
|
+
| Language | Swift 3 |
|
8
|
+
|
9
|
+
This template generate `Decodable` extension for each object of your data model.
|
10
|
+
|
11
|
+
# Generated Code
|
12
|
+
|
13
|
+
`Shop+Decodable.swift` :
|
14
|
+
|
15
|
+
```swift
|
16
|
+
/* DO NOT EDIT | Generated by gyro */
|
17
|
+
|
18
|
+
import protocol Decodable.Decodable
|
19
|
+
import Decodable
|
20
|
+
|
21
|
+
extension Shop: Decodable {
|
22
|
+
|
23
|
+
static func decode(_ json: Any) throws -> Shop {
|
24
|
+
let shop = Shop()
|
25
|
+
shop.attrDate = try Date.decode(json => "attrDate")
|
26
|
+
shop.attrDateCustom = try Date.decode(json => "attrDateCustom")
|
27
|
+
shop.attrDouble = try json => "attrDouble"
|
28
|
+
shop.attrInteger16 = try Int.decode(json => "attrInteger16")
|
29
|
+
shop.attrInteger32 = try json => "attrInteger32"
|
30
|
+
shop.attrInteger64 = try Int.decode(json => "attrInteger64")
|
31
|
+
return shop
|
32
|
+
}
|
33
|
+
}
|
34
|
+
```
|
@@ -0,0 +1,57 @@
|
|
1
|
+
/* DO NOT EDIT | Generated by gyro */
|
2
|
+
|
3
|
+
import protocol Decodable.Decodable
|
4
|
+
import Decodable
|
5
|
+
|
6
|
+
extension {{ entity.name }}: Decodable {
|
7
|
+
|
8
|
+
static func decode(_ json: Any) throws -> {{ entity.name }} {
|
9
|
+
{%- assign entityVariable = entity.name | uncapitalize %}
|
10
|
+
let {{ entityVariable }} = {{ entity.name }}()
|
11
|
+
{%- for attribute in entity.attributes %}
|
12
|
+
{% assign attributeKey = attribute.name -%}
|
13
|
+
{%- if attribute.json_key_path.size > 0 -%}
|
14
|
+
{%- assign attributeKey = attribute.json_key_path -%}
|
15
|
+
{%- endif -%}
|
16
|
+
{%- case attribute.type -%}
|
17
|
+
{%- when "date" -%}
|
18
|
+
{{ entityVariable }}.{{ attribute.name }} = try Date.decode(json => "{{ attributeKey }}")
|
19
|
+
{%- when "integer_16" or "integer_32" or "integer_64" or "float" or "double" or "boolean" -%}
|
20
|
+
{%- if attribute.optional == true -%}
|
21
|
+
{%- if attribute.transformer.size > 0 -%}
|
22
|
+
{{ entityVariable }}.{{ attribute.name }}.value = try {{ attribute.transformer }}.decode(json => "{{ attributeKey }}")
|
23
|
+
{%- else -%}
|
24
|
+
{{ entityVariable }}.{{ attribute.name }}.value = try json => "{{ attributeKey }}"
|
25
|
+
{%- endif -%}
|
26
|
+
{%- else -%}
|
27
|
+
{%- if attribute.transformer.size > 0 -%}
|
28
|
+
{{ entityVariable }}.{{ attribute.name }} = try {{ attribute.transformer }}.decode(json => "{{ attributeKey }}")
|
29
|
+
{%- else -%}
|
30
|
+
{{ entityVariable }}.{{ attribute.name }} = try json => "{{ attributeKey }}"
|
31
|
+
{%- endif -%}
|
32
|
+
{%- endif -%}
|
33
|
+
{%- else -%}
|
34
|
+
{%- if attribute.transformer.size > 0 -%}
|
35
|
+
{{ entityVariable }}.{{ attribute.name }} = try {{ attribute.transformer }}.decode(json => "{{ attributeKey }}")
|
36
|
+
{%- else -%}
|
37
|
+
{{ entityVariable }}.{{ attribute.name }} = try json => "{{ attributeKey }}"
|
38
|
+
{%- endif -%}
|
39
|
+
{%- endcase -%}
|
40
|
+
{%- endfor -%}
|
41
|
+
|
42
|
+
{%- for relationship in entity.relationships %}
|
43
|
+
{% assign relationKey = relationship.name -%}
|
44
|
+
{%- if relationship.json_key_path.size > 0 -%}
|
45
|
+
{%- assign relationKey = relationship.json_key_path -%}
|
46
|
+
{%- endif -%}
|
47
|
+
{%- if relationship.type == "to_many" -%}
|
48
|
+
let {{ relationship.name }}Sandbox: [{{ relationship.inverse_type }}] = try json => "{{ relationKey }}"
|
49
|
+
{{ entityVariable }}.{{ relationship.name }}.append(objectsIn: {{ relationship.name }}Sandbox)
|
50
|
+
{%- else -%}
|
51
|
+
{{ entityVariable }}.{{ relationship.name }} = try json => "{{ relationKey }}"
|
52
|
+
{%- endif -%}
|
53
|
+
{%- endfor %}
|
54
|
+
return {{ entityVariable }}
|
55
|
+
}
|
56
|
+
|
57
|
+
}
|