gyro 0.4.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +42 -797
  3. data/bin/gyro +91 -84
  4. data/documentation/enum.png +0 -0
  5. data/documentation/enum_json.png +0 -0
  6. data/documentation/ignored.png +0 -0
  7. data/documentation/json.png +0 -0
  8. data/documentation/primary_key.png +0 -0
  9. data/documentation/read_only.png +0 -0
  10. data/documentation/simple_entity.png +0 -0
  11. data/documentation/support_annotation.png +0 -0
  12. data/documentation/transformer.png +0 -0
  13. data/documentation/transformers.png +0 -0
  14. data/lib/gyro.rb +18 -29
  15. data/lib/gyro/generator/json.rb +30 -0
  16. data/lib/gyro/generator/liquid.rb +22 -0
  17. data/lib/gyro/generator/liquid/filters.rb +53 -0
  18. data/lib/gyro/generator/liquid/liquid.rb +124 -0
  19. data/lib/gyro/generator/liquid/whitespace_patch.rb +61 -0
  20. data/lib/gyro/log.rb +46 -0
  21. data/lib/gyro/parser/xcdatamodel.rb +20 -0
  22. data/lib/gyro/parser/xcdatamodel/attribute.rb +129 -0
  23. data/lib/gyro/parser/xcdatamodel/entity.rb +195 -0
  24. data/lib/gyro/parser/xcdatamodel/relationship.rb +84 -0
  25. data/lib/gyro/parser/xcdatamodel/xcdatamodel.rb +65 -0
  26. data/lib/gyro/template.rb +68 -0
  27. data/lib/gyro/version.rb +19 -0
  28. data/lib/templates/android/README.md +164 -0
  29. data/lib/templates/android/entity.liquid +49 -0
  30. data/lib/templates/android/entity_filename.liquid +1 -0
  31. data/lib/templates/android/enum.liquid +44 -0
  32. data/lib/templates/android/enum_filename.liquid +1 -0
  33. data/lib/templates/android/inc/_attributes_enum.liquid +17 -0
  34. data/lib/templates/android/inc/_attributes_getter_setter.liquid +58 -0
  35. data/lib/templates/android/inc/_attributes_properties.liquid +35 -0
  36. data/lib/templates/android/inc/_enum_getter_setter.liquid +19 -0
  37. data/lib/templates/android/inc/_primitives.liquid +30 -0
  38. data/lib/templates/android/inc/_relationships_enum.liquid +14 -0
  39. data/lib/templates/android/inc/_relationships_getter_setter.liquid +47 -0
  40. data/lib/templates/android/inc/_relationships_properties.liquid +27 -0
  41. data/lib/templates/android/inc/_type_converter.liquid +22 -0
  42. data/lib/templates/android/inc/_wrapper_type_converter.liquid +22 -0
  43. data/lib/templates/decodable/README.md +34 -0
  44. data/lib/templates/decodable/entity.liquid +57 -0
  45. data/lib/templates/decodable/entity_filename.liquid +1 -0
  46. data/lib/templates/decodable/enum.liquid +0 -0
  47. data/lib/templates/decodable/enum_filename.liquid +0 -0
  48. data/lib/templates/object-mapper/README.md +40 -0
  49. data/lib/templates/object-mapper/entity.liquid +66 -0
  50. data/lib/templates/object-mapper/entity_filename.liquid +1 -0
  51. data/lib/templates/object-mapper/enum.liquid +0 -0
  52. data/lib/templates/object-mapper/enum_filename.liquid +0 -0
  53. data/lib/templates/swift3-variant/README.md +60 -0
  54. data/lib/templates/swift3-variant/entity.liquid +12 -0
  55. data/lib/templates/swift3-variant/entity_filename.liquid +1 -0
  56. data/lib/templates/swift3-variant/enum.liquid +15 -0
  57. data/lib/templates/swift3-variant/enum_filename.liquid +1 -0
  58. data/lib/templates/swift3-variant/inc/_attributes_enum.liquid +13 -0
  59. data/lib/templates/swift3-variant/inc/_attributes_properties.liquid +32 -0
  60. data/lib/templates/swift3-variant/inc/_default_value_converter.liquid +14 -0
  61. data/lib/templates/swift3-variant/inc/_enum_attribute_property.liquid +26 -0
  62. data/lib/templates/swift3-variant/inc/_ignored_properties.liquid +24 -0
  63. data/lib/templates/swift3-variant/inc/_indexed_properties.liquid +19 -0
  64. data/lib/templates/swift3-variant/inc/_inverse_properties.liquid +11 -0
  65. data/lib/templates/swift3-variant/inc/_optional_attribute_property.liquid +5 -0
  66. data/lib/templates/swift3-variant/inc/_primary_key.liquid +5 -0
  67. data/lib/templates/swift3-variant/inc/_relationship_properties.liquid +9 -0
  68. data/lib/templates/swift3-variant/inc/_relationships_enum.liquid +17 -0
  69. data/lib/templates/swift3-variant/inc/_type_converter.liquid +20 -0
  70. data/lib/templates/swift3/README.md +60 -0
  71. data/lib/templates/swift3/entity.liquid +12 -0
  72. data/lib/templates/swift3/entity_filename.liquid +1 -0
  73. data/lib/templates/swift3/enum.liquid +15 -0
  74. data/lib/templates/swift3/enum_filename.liquid +1 -0
  75. data/lib/templates/swift3/inc/_attributes_enum.liquid +13 -0
  76. data/lib/templates/swift3/inc/_attributes_properties.liquid +32 -0
  77. data/lib/templates/swift3/inc/_default_value_converter.liquid +14 -0
  78. data/lib/templates/swift3/inc/_enum_attribute_property.liquid +26 -0
  79. data/lib/templates/swift3/inc/_ignored_properties.liquid +24 -0
  80. data/lib/templates/swift3/inc/_indexed_properties.liquid +19 -0
  81. data/lib/templates/swift3/inc/_inverse_properties.liquid +11 -0
  82. data/lib/templates/swift3/inc/_optional_attribute_property.liquid +5 -0
  83. data/lib/templates/swift3/inc/_primary_key.liquid +5 -0
  84. data/lib/templates/swift3/inc/_relationship_properties.liquid +9 -0
  85. data/lib/templates/swift3/inc/_relationships_enum.liquid +17 -0
  86. data/lib/templates/swift3/inc/_type_converter.liquid +20 -0
  87. metadata +134 -31
  88. data/lib/gyro/realm/java/converter.rb +0 -63
  89. data/lib/gyro/realm/java/enum_generator.rb +0 -128
  90. data/lib/gyro/realm/java/generator.rb +0 -183
  91. data/lib/gyro/realm/java/templates.rb +0 -67
  92. data/lib/gyro/realm/objc/converter.rb +0 -63
  93. data/lib/gyro/realm/objc/enum_generator.rb +0 -86
  94. data/lib/gyro/realm/objc/generator.rb +0 -373
  95. data/lib/gyro/realm/objc/json_category_generator.rb +0 -172
  96. data/lib/gyro/realm/objc/protocol_generator.rb +0 -59
  97. data/lib/gyro/realm/objc/templates.rb +0 -100
  98. data/lib/gyro/realm/swift/converter.rb +0 -74
  99. data/lib/gyro/realm/swift/enum_generator.rb +0 -73
  100. data/lib/gyro/realm/swift/generator.rb +0 -265
  101. data/lib/gyro/realm/swift/object_mapper_generator.rb +0 -124
  102. data/lib/gyro/realm/swift/templates.rb +0 -64
  103. data/lib/gyro/utils/file_utils.rb +0 -31
  104. data/lib/gyro/utils/log.rb +0 -68
  105. data/lib/gyro/utils/raise.rb +0 -23
  106. data/lib/gyro/utils/string_xcdatamodel.rb +0 -58
  107. data/lib/gyro/xcdatamodel/parser/attribute.rb +0 -98
  108. data/lib/gyro/xcdatamodel/parser/entity.rb +0 -234
  109. data/lib/gyro/xcdatamodel/parser/relationship.rb +0 -70
  110. data/lib/gyro/xcdatamodel/parser/xcdatamodel.rb +0 -59
@@ -0,0 +1 @@
1
+ {{name}}+Decodable.swift
File without changes
File without changes
@@ -0,0 +1,40 @@
1
+ # ObjectMapper Template Information
2
+
3
+ | Name | Description |
4
+ | --------- | ----------------- |
5
+ | Folder name | templates/object-mapper |
6
+ | Invocation example | `gyro -m <model> -t object-mapper …` |
7
+ | Language | Swift 3 |
8
+
9
+ This template generate `ObjectMapper` extension for each object of your data model.
10
+
11
+ # Generated Code
12
+
13
+ `ShopMapper.swift` :
14
+
15
+ ```swift
16
+ /* DO NOT EDIT | Generated by gyro */
17
+
18
+ import ObjectMapper
19
+
20
+ extension Shop: Mappable {
21
+
22
+ // MARK: Initializers
23
+ convenience init?(map: Map) {
24
+ self.init()
25
+ }
26
+
27
+ // MARK: Mappable
28
+ func mapping(map: Map) {
29
+ // MARK: Attributes
30
+ self.attrDate <- (map["attrDate"], ISO8601DateTransform())
31
+ self.attrDateCustom <- (map["attrDateCustom"], CustomDateTransformer())
32
+ self.attrDecimal <- (map["attrDecimal"], MPDecimalTransformer())
33
+ self.attrDouble <- map["attrDouble"]
34
+ self.attrFloat <- (map["attrFloat"], MPDecimalTransformer())
35
+ self.attrInteger16 <- (map["attrInteger16"], MPIntegerTransformer())
36
+ self.attrInteger32 <- map["attrInteger32"]
37
+ self.attrInteger64 <- (map["attrInteger64"], MPIntegerTransformer())
38
+ }
39
+ }
40
+ ```
@@ -0,0 +1,66 @@
1
+ /* DO NOT EDIT | Generated by gyro */
2
+
3
+ import ObjectMapper
4
+
5
+ extension {{ entity.name }}: Mappable {
6
+
7
+ // MARK: Initializers
8
+ convenience init?(map: Map) {
9
+ self.init()
10
+ }
11
+
12
+ // MARK: Mappable
13
+ func mapping(map: Map) {
14
+ {%- if entity.attributes.size > 0 %}
15
+ // MARK: Attributes
16
+ {%- endif -%}
17
+ {%- for attribute in entity.attributes -%}
18
+ {% assign attributeKey = attribute.name -%}
19
+ {%- if attribute.json_key_path.size > 0 -%}
20
+ {%- assign attributeKey = attribute.json_key_path -%}
21
+ {%- endif -%}
22
+
23
+ {%- case attribute.type -%}
24
+ {%- when "date" -%}
25
+ {%- assign transformer = "ISO8601DateTransform" -%}
26
+ {%- if attribute.transformer.size > 0 -%}
27
+ {%- assign transformer = attribute.transformer -%}
28
+ {%- endif %}
29
+ self.{{ attribute.name }} <- (map["{{ attributeKey }}"], {{ transformer }}())
30
+ {%- when "integer_16" or "integer_32" or "integer_64" or "float" or "double" or "boolean" -%}
31
+ {%- if attribute.optional == true and attribute.enum_type.size == 0 %}
32
+ self.{{ attribute.name }}.value <- map["{{ attributeKey }}"]
33
+ {%- else %}
34
+ {%- if attribute.transformer.size > 0 %}
35
+ self.{{ attribute.name }} <- (map["{{ attributeKey }}"], {{ attribute.transformer }}())
36
+ {%- else %}
37
+ self.{{ attribute.name }} <- map["{{ attributeKey }}"]
38
+ {%- endif %}
39
+ {%- endif -%}
40
+ {%- else %}
41
+ {%- if attribute.transformer.size > 0 %}
42
+ self.{{ attribute.name }} <- (map["{{ attributeKey }}"], {{ attribute.transformer }}())
43
+ {%- else %}
44
+ self.{{ attribute.name }} <- map["{{ attributeKey }}"]
45
+ {%- endif %}
46
+ {%- endcase -%}
47
+ {%- endfor -%}
48
+ {%- if entity.relationships.size > 0 %}
49
+
50
+ // MARK: Relationships
51
+ {%- endif -%}
52
+ {%- for relationship in entity.relationships -%}
53
+ {%- if relationship.inverse == false -%}
54
+ {% assign relationKey = relationship.name -%}
55
+ {%- if relationship.json_key_path.size > 0 -%}
56
+ {%- assign relationKey = relationship.json_key_path -%}
57
+ {%- endif -%}
58
+ {%- if relationship.type == "to_many" %}
59
+ self.{{ relationship.name }} <- (map["{{ relationKey }}"], ListTransform<{{ relationship.inverse_type }}>())
60
+ {%- else %}
61
+ self.{{ relationship.name }} <- map["{{ relationKey }}"]
62
+ {%- endif -%}
63
+ {%- endif -%}
64
+ {%- endfor %}
65
+ }
66
+ }
@@ -0,0 +1 @@
1
+ {{name}}Mapper.swift
File without changes
File without changes
@@ -0,0 +1,60 @@
1
+ # Swift3 variant Template Information
2
+
3
+ | Name | Description |
4
+ | --------- | ----------------- |
5
+ | Folder name | templates/swift3-variant |
6
+ | Invocation example | `gyro -m <model> -t swift3-variant …` |
7
+ | Language | Swift 3 |
8
+
9
+ # When to use it
10
+
11
+ When you need to work with `ObjectMapper` and `Realm` together
12
+
13
+ # Caracteristics
14
+
15
+ In this template optional Realm objects (Attributes - RealmOptional - or Relationships - List<> -) are var properties :
16
+
17
+ ```
18
+ // Attribute generation
19
+ {%- if attribute.is_number == true or attribute.is_bool == true %}
20
+ var {{ attribute.name }} = RealmOptional<{{ convert_type }}>()
21
+ {%- else %}
22
+ dynamic var {{ attribute.name }}: {{ convert_type }}?
23
+ {%- endif -%}
24
+
25
+ // Relationship generation
26
+ {%- if relationship.inverse == false %}
27
+ {%- if relationship.type == "to_many" %}
28
+ var {{ relationship.name }} = List<{{ relationship.inverse_type }}>()
29
+ {%- else %}
30
+ dynamic var {{ relationship.name }}: {{ relationship.inverse_type }}?
31
+ {%- endif %}
32
+ {%- endif %}
33
+ ```
34
+
35
+ # Generated Code
36
+
37
+ `Product.swift`
38
+
39
+ ```swift
40
+ /* DO NOT EDIT | Generated by gyro */
41
+
42
+ import RealmSwift
43
+
44
+ final class Product: Object {
45
+
46
+ enum Attributes: String {
47
+ case brand = "brand"
48
+ case name = "name"
49
+ case price = "price"
50
+ case users = "users"
51
+ }
52
+
53
+ dynamic var brand: String?
54
+ dynamic var name: String = ""
55
+ var price = RealmOptional<Int32>()
56
+
57
+ var users = List<Users>()
58
+ }
59
+
60
+ ```
@@ -0,0 +1,12 @@
1
+ /* DO NOT EDIT | Generated by gyro */
2
+
3
+ import RealmSwift
4
+
5
+ final class {{ entity.name }}: Object {
6
+ {%- include 'inc/attributes_enum' -%}
7
+ {% include 'inc/relationships_enum' -%}
8
+ {% include 'inc/attributes_properties' %}
9
+ {% include 'inc/primary_key' -%}
10
+ {% include 'inc/indexed_properties' -%}
11
+ {% include 'inc/ignored_properties' %}
12
+ }
@@ -0,0 +1 @@
1
+ {{params.prefix}}{{name}}.swift
@@ -0,0 +1,15 @@
1
+ {%- if attribute.enum_type.size > 0 -%}
2
+ /* DO NOT EDIT | Generated by gyro */
3
+
4
+ enum {{ params.prefix }}{{ attribute.enum_type }}: String {
5
+ {%- for value in attribute.enum_values %}
6
+ {%- if attribute.enum_values.size > 0 %}
7
+ {% assign jsonKey = value -%}
8
+ {%- if attribute.json_values.size > 0 and attribute.json_values[forloop.index0] -%}
9
+ {%- assign jsonKey = attribute.json_values[forloop.index0] -%}
10
+ {%- endif -%}
11
+ case {{ value | uncapitalize }} = "{{ jsonKey | escape_quotes }}"
12
+ {%- endif %}
13
+ {%- endfor %}
14
+ }
15
+ {% endif %}
@@ -0,0 +1 @@
1
+ {{params.prefix}}{{name}}.swift
@@ -0,0 +1,13 @@
1
+
2
+ {% if entity.attributes.size > 0 %}
3
+ enum Attributes: String {
4
+ {%- for attribute in entity.attributes -%}
5
+ {%- if attribute.realm_ignored or attribute.realm_read_only.size == 0 -%}
6
+ {%- if attribute.comment.size > 0 %}
7
+ /** {{ attribute.comment }} **/
8
+ {%- endif %}
9
+ case {{ attribute.name }} = "{{ attribute.name | escape_quotes }}"
10
+ {%- endif %}
11
+ {%- endfor %}
12
+ }
13
+ {% endif -%}
@@ -0,0 +1,32 @@
1
+ {%- for attribute in entity.attributes -%}
2
+ {%- comment %} ******* DEFAULT VALUE CAPTURE ******* {% endcomment -%}
3
+ {%- capture default_value -%}
4
+ {%- include 'inc/default_value_converter' -%}
5
+ {%- endcapture -%}
6
+
7
+ {%- comment %} ******* CONVERT TYPE CAPTURE ******* {% endcomment -%}
8
+ {%- capture convert_type -%}
9
+ {%- include 'inc/type_converter' -%}
10
+ {%- endcapture -%}
11
+
12
+ {%- if attribute.realm_read_only.size == 0 -%}
13
+ {%- if attribute.enum_values.size > 0 -%}
14
+ {%- comment -%} ******* GENERATE ENUM ATTRIBUTE PROPERTY ******* {% endcomment -%}
15
+ {%- include 'inc/enum_attribute_property' -%}
16
+ {%- else -%}
17
+ {%- if attribute.optional == true -%}
18
+ {% comment -%} ******* GENERATE OPTIONAL ATTRIBUTE PROPERTY ******* {% endcomment -%}
19
+ {%- include 'inc/optional_attribute_property' -%}
20
+ {%- else -%}
21
+ {%- comment -%} ******* GENERATE DEFAULT ATTRIBUTE PROPERTY ******* {% endcomment %}
22
+ dynamic var {{ attribute.name }}: {{ convert_type }} = {{ default_value }}
23
+ {%- endif -%}
24
+ {%- endif -%}
25
+ {%- endif -%}
26
+ {%- endfor -%}
27
+
28
+ {%- comment %} ******* GENERATE RELATIONSHIP PROPERTIES ******* {% endcomment %}
29
+ {%- include 'inc/relationship_properties' -%}
30
+
31
+ {%- comment %} ******* GENERATE INVERSE PROPERTIES ******* {% endcomment -%}
32
+ {%- include 'inc/inverse_properties' -%}
@@ -0,0 +1,14 @@
1
+ {%- case attribute.type -%}
2
+ {%- when 'integer_16' or 'integer_32' or 'integer_64' -%}
3
+ 0
4
+ {%- when 'float' or 'double' or 'decimal' -%}
5
+ 0.0
6
+ {%- when 'string' -%}
7
+ ""
8
+ {%- when 'boolean' -%}
9
+ false
10
+ {%- when 'date' -%}
11
+ Date()
12
+ {%- when 'binary' -%}
13
+ Data()
14
+ {%- endcase -%}
@@ -0,0 +1,26 @@
1
+ {%- if attribute.optional == true %}
2
+
3
+ dynamic var {{ attribute.name }}: String?
4
+ {%- else %}
5
+
6
+ dynamic var {{ attribute.name }}: String = ""
7
+ {%- endif %}
8
+ {%- assign enum_type = attribute.enum_type %}
9
+ {%- assign enum_name = attribute.name %}
10
+ var {{ enum_name }}Enum: {{ enum_type }}? {
11
+ get {
12
+ {%- if attribute.optional == true %}
13
+ guard let {{ attribute.name }} = {{ attribute.name }},
14
+ let enumValue = {{ enum_type }}(rawValue: {{ attribute.name }})
15
+ else { return nil }
16
+ {%- else %}
17
+ guard let enumValue = {{ enum_type }}(rawValue: {{ attribute.name }}) else { return nil }
18
+ {%- endif %}
19
+ return enumValue
20
+ }
21
+ {%- if attribute.optional == true %}
22
+ set { {{ attribute.name }} = newValue?.rawValue ?? nil }
23
+ {%- else %}
24
+ set { {{ attribute.name }} = newValue?.rawValue ?? "" }
25
+ {%- endif %}
26
+ }
@@ -0,0 +1,24 @@
1
+ {%- if entity.has_ignored == true %}
2
+ // Specify properties to ignore (Realm won't persist these)
3
+ override static func ignoredProperties() -> [String] {
4
+ return [
5
+ {%- capture enum_ignored_properties -%}
6
+ {%- for attribute in entity.attributes -%}
7
+ {%- if attribute.realm_ignored == true -%}
8
+ "{{ attribute.name }}",
9
+ {%- endif -%}
10
+ {%- endfor -%}
11
+
12
+ {%- for relationship in entity.relationships -%}
13
+ {%- if relationship.realm_ignored == true -%}
14
+ "{{ relationship.name }}",
15
+ {%- endif -%}
16
+ {%- endfor -%}
17
+ {%- endcapture -%}
18
+
19
+ {%- assign enum_ignored_properties_array = enum_ignored_properties | split: "," -%}
20
+ {%- for item in enum_ignored_properties_array -%}
21
+ {{ item }}{%- if forloop.last == false -%},{%- endif -%}
22
+ {%- endfor -%}]
23
+ }
24
+ {% endif -%}
@@ -0,0 +1,19 @@
1
+ {%- if entity.has_indexed_attributes == true %}
2
+ // Specify properties to index
3
+ override static func indexedProperties() -> [String] {
4
+ return [
5
+ {%- capture enum_indexed_properties -%}
6
+ {%- for attribute in entity.attributes -%}
7
+ {%- if attribute.is_indexed == true -%}
8
+ "{{attribute.name}}",
9
+ {%- endif %}
10
+ {%- endfor %}
11
+ {%- endcapture -%}
12
+
13
+ {%- assign enum_indexed_properties_array = enum_indexed_properties | split: "," -%}
14
+ {%- assign enum_indexed_properties_array_size = enum_indexed_properties_array | size | minus: 1 -%}
15
+ {%- for item in enum_indexed_properties_array limit:enum_indexed_properties_array_size -%}
16
+ {{ item }}{%- if forloop.last == false -%},{%- endif -%}
17
+ {%- endfor -%}]
18
+ }
19
+ {%- endif -%}
@@ -0,0 +1,11 @@
1
+ {%- for relationship in entity.relationships -%}
2
+ {%- if relationship.inverse == true %}
3
+ {% assign name_size = relationship.name | size | minus: 1 %}
4
+ {%- if relationship.type == "to_many" %}
5
+ let {{ relationship.name | truncate: name_size, '' }}s = LinkingObjects(fromType: {{ relationship.inverse_type }}.self, property: "{{ relationship.inverse_name }}")
6
+ {%- else %}
7
+ let {{ relationship.name | truncate: name_size, '' }}s = LinkingObjects(fromType: {{ relationship.inverse_type }}.self, property: "{{ relationship.inverse_name }}")
8
+ var {{ relationship.name | truncate: name_size, '' }}: {{ relationship.inverse_type }}? { return {{ relationship.name | truncate: name_size, '' }}s.first }
9
+ {%- endif -%}
10
+ {%- endif -%}
11
+ {%- endfor -%}
@@ -0,0 +1,5 @@
1
+ {%- if attribute.is_number == true or attribute.is_bool == true %}
2
+ var {{ attribute.name }} = RealmOptional<{{ convert_type }}>()
3
+ {%- else %}
4
+ dynamic var {{ attribute.name }}: {{ convert_type }}?
5
+ {%- endif -%}
@@ -0,0 +1,5 @@
1
+ {%- if entity.has_primary_key == true %}
2
+ override static func primaryKey() -> String? {
3
+ return "{{ entity.identity_attribute }}"
4
+ }
5
+ {% endif -%}
@@ -0,0 +1,9 @@
1
+ {%- for relationship in entity.relationships -%}
2
+ {%- if relationship.inverse == false %}
3
+ {%- if relationship.type == "to_many" %}
4
+ var {{ relationship.name }} = List<{{ relationship.inverse_type }}>()
5
+ {%- else %}
6
+ dynamic var {{ relationship.name }}: {{ relationship.inverse_type }}?
7
+ {%- endif %}
8
+ {%- endif %}
9
+ {%- endfor -%}
@@ -0,0 +1,17 @@
1
+ {%- if entity.relationships.size > 0 and entity.has_only_inverse == false %}
2
+ enum Relationships: String {
3
+ {%- for relationship in entity.relationships %}
4
+ {%- capture relationship_name -%}
5
+ {%- if relationship.inverse == true -%}
6
+ {%- assign name_size = relationship.name | size | minus: 1 -%}
7
+ {{ relationship.name | truncate: name_size, '' }}
8
+ {%- if relationship.type == "to_many" -%}s{%- endif -%}
9
+ {%- else -%}
10
+ {{ relationship.name }}
11
+ {%- endif -%}
12
+ {%- endcapture -%}
13
+ {%- assign relationship_name = relationship_name %}
14
+ case {{ relationship_name | uncapitalize }} = "{{ relationship_name | escape_quotes }}"
15
+ {%- endfor %}
16
+ }
17
+ {% endif -%}
@@ -0,0 +1,20 @@
1
+ {%- case attribute.type -%}
2
+ {%- when 'integer_16' -%}
3
+ Int16
4
+ {%- when 'integer_32' -%}
5
+ Int32
6
+ {%- when 'integer_64' -%}
7
+ Int64
8
+ {%- when 'double' or 'decimal' -%}
9
+ Double
10
+ {%- when 'float' -%}
11
+ Float
12
+ {%- when 'string' -%}
13
+ String
14
+ {%- when 'boolean' -%}
15
+ Bool
16
+ {%- when 'date' -%}
17
+ Date
18
+ {%- when 'binary' -%}
19
+ Data
20
+ {%- endcase -%}
@@ -0,0 +1,60 @@
1
+ # Swift3 Template Information
2
+
3
+ | Name | Description |
4
+ | --------- | ----------------- |
5
+ | Folder name | templates/swift3 |
6
+ | Invocation example | `gyro -m <model> -t swift3 …` |
7
+ | Language | Swift 3 |
8
+
9
+ # When to use it
10
+
11
+ This template is the reference for swift 3 with Realm generation code.
12
+ You can use it when you need to work with `Realm`
13
+
14
+ # Caracteristics
15
+
16
+ In this template optional Realm objects (Attributes - RealmOptional - or Relationships - List<> -) are `let` properties (conform to the Realm documentation) :
17
+
18
+ ```
19
+ // Attribute generation
20
+ {%- if attribute.is_number == true or attribute.is_bool == true %}
21
+ let {{ attribute.name }} = RealmOptional<{{ convert_type }}>()
22
+ {%- else %}
23
+ dynamic var {{ attribute.name }}: {{ convert_type }}?
24
+ {%- endif -%}
25
+
26
+ // Relationship generation
27
+ {%- if relationship.inverse == false %}
28
+ {%- if relationship.type == "to_many" %}
29
+ let {{ relationship.name }} = List<{{ relationship.inverse_type }}>()
30
+ {%- else %}
31
+ dynamic var {{ relationship.name }}: {{ relationship.inverse_type }}?
32
+ {%- endif %}
33
+ {%- endif %}
34
+ ```
35
+
36
+ # Generated Code
37
+
38
+ `Product.swift` :
39
+
40
+ ```swift
41
+ /* DO NOT EDIT | Generated by gyro */
42
+
43
+ import RealmSwift
44
+
45
+ final class Product: Object {
46
+
47
+ enum Attributes: String {
48
+ case brand = "brand"
49
+ case name = "name"
50
+ case price = "price"
51
+ case users = "users"
52
+ }
53
+
54
+ dynamic var brand: String?
55
+ dynamic var name: String = ""
56
+ let price = RealmOptional<Int32>()
57
+
58
+ let users = List<Users>()
59
+ }
60
+ ```