gyro 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gyro/parser/xcdatamodel/attribute.rb +4 -1
- data/lib/gyro/parser/xcdatamodel/relationship.rb +5 -2
- data/lib/gyro/version.rb +1 -1
- data/lib/templates/android/inc/_attributes_properties.liquid +14 -3
- data/lib/templates/android/inc/_relationships_getter_setter.liquid +1 -1
- data/lib/templates/android/inc/_relationships_properties.liquid +1 -1
- data/lib/templates/decodable/README.md +6 -0
- data/lib/templates/decodable/entity.liquid +47 -19
- data/lib/templates/swift3-variant/inc/_default_value_converter.liquid +23 -3
- data/lib/templates/swift3/README.md +1 -1
- data/lib/templates/swift3/inc/_default_value_converter.liquid +23 -3
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15960f1f9c3d4bdb80d4cd3edfb5a7380b79c72c
|
4
|
+
data.tar.gz: 58e1994395f309312e639e61287a80ae0a00514b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b270fc1099b7e5485179085b1e88666d4e95270fb3ab3188a5987924cfcc19f2809e9a044e748869e88f999be9c61ab8bba700774e46b9bf8fa89c2105bfcf8a
|
7
|
+
data.tar.gz: 718cce84c7e01a71f5dd35ea8898a79220ac6dc50aeee8cf7f995bd6aeafd2411b211b8ff87e43dec9141750b836efaef4d11a38c6c86fb1c0e52d13c5dc8caf
|
@@ -20,11 +20,12 @@ module Gyro
|
|
20
20
|
class Attribute
|
21
21
|
attr_accessor :entity_name, :name, :type, :optional, :indexed, :default
|
22
22
|
attr_accessor :realm_ignored, :realm_read_only, :enum_type, :enum_values
|
23
|
-
attr_accessor :json_key_path, :json_values, :transformer, :comment, :support_annotation
|
23
|
+
attr_accessor :json_key_path, :json_values, :transformer, :comment, :support_annotation, :json_ignored
|
24
24
|
|
25
25
|
alias optional? optional
|
26
26
|
alias indexed? indexed
|
27
27
|
alias realm_ignored? realm_ignored
|
28
|
+
alias json_ignored? json_ignored
|
28
29
|
|
29
30
|
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
30
31
|
def initialize(attribute_xml, entity_name)
|
@@ -40,6 +41,7 @@ module Gyro
|
|
40
41
|
@enum_values = Gyro::Parser::XCDataModel.user_info(attribute_xml, 'enumValues').split(',')
|
41
42
|
@json_key_path = Gyro::Parser::XCDataModel.user_info(attribute_xml, 'JSONKeyPath')
|
42
43
|
@json_values = Gyro::Parser::XCDataModel.user_info(attribute_xml, 'JSONValues').split(',')
|
44
|
+
@json_ignored = !Gyro::Parser::XCDataModel.user_info(attribute_xml, 'JSONIgnored').empty?
|
43
45
|
@transformer = Gyro::Parser::XCDataModel.user_info(attribute_xml, 'transformer').strip
|
44
46
|
@comment = Gyro::Parser::XCDataModel.user_info(attribute_xml, 'comment')
|
45
47
|
@support_annotation = Gyro::Parser::XCDataModel.user_info(attribute_xml, 'supportAnnotation')
|
@@ -56,6 +58,7 @@ module Gyro
|
|
56
58
|
'realm_ignored' => realm_ignored, 'realm_read_only' => realm_read_only,
|
57
59
|
'enum_type' => enum_type, 'enum_values' => enum_values,
|
58
60
|
'json_key_path' => json_key_path, 'json_values' => json_values,
|
61
|
+
'json_ignored' => json_ignored,
|
59
62
|
'transformer' => transformer, 'need_transformer' => need_transformer?,
|
60
63
|
'comment' => comment,
|
61
64
|
'support_annotation' => support_annotation,
|
@@ -19,11 +19,12 @@ module Gyro
|
|
19
19
|
#
|
20
20
|
class Relationship
|
21
21
|
attr_accessor :entity_name, :name, :type, :optional, :deletion_rule
|
22
|
-
attr_accessor :inverse_name, :inverse_type, :json_key_path, :support_annotation
|
22
|
+
attr_accessor :inverse_name, :inverse_type, :json_key_path, :support_annotation, :json_ignored
|
23
23
|
attr_accessor :realm_ignored
|
24
24
|
attr_accessor :destination
|
25
25
|
|
26
26
|
alias realm_ignored? realm_ignored
|
27
|
+
alias json_ignored? json_ignored
|
27
28
|
|
28
29
|
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
29
30
|
def initialize(relationship_xml, entity_name)
|
@@ -35,6 +36,7 @@ module Gyro
|
|
35
36
|
@inverse_type = relationship_xml.attributes['destinationEntity'].to_s
|
36
37
|
@json_key_path = Gyro::Parser::XCDataModel.user_info(relationship_xml, 'JSONKeyPath')
|
37
38
|
@realm_ignored = Gyro::Parser::XCDataModel.user_info(relationship_xml, 'realmIgnored').empty? ? false : true
|
39
|
+
@json_ignored = Gyro::Parser::XCDataModel.user_info(relationship_xml, 'JSONIgnored').empty? ? false : true
|
38
40
|
@support_annotation = Gyro::Parser::XCDataModel.user_info(relationship_xml, 'supportAnnotation')
|
39
41
|
load_type(relationship_xml)
|
40
42
|
@destination = Gyro::Parser::XCDataModel.user_info(relationship_xml, 'destination')
|
@@ -45,7 +47,8 @@ module Gyro
|
|
45
47
|
{ 'entity_name' => entity_name, 'name' => name, 'type' => type.to_s,
|
46
48
|
'optional' => optional, 'deletion_rule' => deletion_rule,
|
47
49
|
'inverse_name' => inverse_name, 'inverse_type' => inverse_type,
|
48
|
-
'json_key_path' => json_key_path, '
|
50
|
+
'json_key_path' => json_key_path, 'json_ignored' => json_ignored,
|
51
|
+
'support_annotation' => support_annotation,
|
49
52
|
'realm_ignored' => realm_ignored, 'destination' => destination, 'inverse' => inverse? }
|
50
53
|
end
|
51
54
|
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
data/lib/gyro/version.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
{%- for attribute in entity.attributes -%}
|
1
|
+
{% for attribute in entity.attributes -%}
|
3
2
|
{%- if attribute.realm_read_only.size == 0 -%}
|
4
3
|
{%- comment %} ******* CONVERT TYPE CAPTURE ******* {% endcomment -%}
|
5
4
|
{%- capture convert_type -%}
|
@@ -14,6 +13,18 @@
|
|
14
13
|
{%- endif -%}
|
15
14
|
{%- endcapture -%}
|
16
15
|
|
16
|
+
{%- capture default_value %}
|
17
|
+
{%- if attribute.default.size > 0 %} =
|
18
|
+
{%- if convert_type == "boolean" %}
|
19
|
+
{%- if attribute.default == "YES" %} true
|
20
|
+
{%- else %} false
|
21
|
+
{%- endif %}
|
22
|
+
{%- elsif convert_type == "String" %} "{{ attribute.default }}"
|
23
|
+
{%- else %} {{ attribute.default }}
|
24
|
+
{%- endif %}
|
25
|
+
{%- endif %}
|
26
|
+
{%- endcapture %}
|
27
|
+
|
17
28
|
{%- assign name = attribute.name -%}
|
18
29
|
{%- if name == primary_key %}
|
19
30
|
@PrimaryKey
|
@@ -30,6 +41,6 @@
|
|
30
41
|
{%- if params.support_annotations.size > 0 and attribute.support_annotation.size > 0 %}
|
31
42
|
@android.support.annotation.{{ attribute.support_annotation }}
|
32
43
|
{%- endif %}
|
33
|
-
private {{ convert_type }} {{ name }};
|
44
|
+
private {{ convert_type }} {{ name }}{{ default_value }};
|
34
45
|
{%- endif -%}
|
35
46
|
{%- endfor -%}
|
@@ -34,3 +34,9 @@ extension Shop: Decodable {
|
|
34
34
|
}
|
35
35
|
}
|
36
36
|
```
|
37
|
+
|
38
|
+
# Specific JSON tasks
|
39
|
+
|
40
|
+
## Ignoring specific properties
|
41
|
+
|
42
|
+
If you don't want to generate a decodable call for a specific property, just add the `JSONIgnored` attribute in the xcdatamodel property's userInfos.
|
@@ -8,49 +8,77 @@ extension {{ entity.name }}: Decodable {
|
|
8
8
|
static func decode(_ json: Any) throws -> {{ entity.name }} {
|
9
9
|
{%- assign entityVariable = entity.name | uncapitalize %}
|
10
10
|
let {{ entityVariable }} = {{ entity.name }}()
|
11
|
+
|
11
12
|
{%- for attribute in entity.attributes %}
|
12
|
-
|
13
|
+
{%- if attribute.json_ignored == false %}
|
14
|
+
{%- assign trySyntax = "try" -%}
|
15
|
+
{%- if attribute.optional == true -%}
|
16
|
+
{%- assign trySyntax = "try?" -%}
|
17
|
+
{%- endif -%}
|
18
|
+
{%- assign attributeKey = attribute.name -%}
|
13
19
|
{%- if attribute.json_key_path.size > 0 -%}
|
14
20
|
{%- assign attributeKey = attribute.json_key_path -%}
|
15
21
|
{%- endif -%}
|
16
22
|
{%- case attribute.type -%}
|
17
|
-
{%- when "date"
|
18
|
-
{{ entityVariable }}.{{ attribute.name }} =
|
23
|
+
{%- when "date" %}
|
24
|
+
{{ entityVariable }}.{{ attribute.name }} = {{ trySyntax }} Date.decode(json => "{{ attributeKey }}")
|
19
25
|
{%- when "integer_16" or "integer_32" or "integer_64" or "float" or "double" or "boolean" -%}
|
20
26
|
{%- if attribute.optional == true -%}
|
21
|
-
{%- if attribute.
|
22
|
-
|
27
|
+
{%- if attribute.enum_values.size > 0 -%}
|
28
|
+
{%- if attribute.transformer.size > 0 %}
|
29
|
+
{{ entityVariable }}.{{ attribute.name }} = {{ trySyntax }} {{ attribute.transformer }}.decode(json => "{{ attributeKey }}")
|
30
|
+
{%- else %}
|
31
|
+
{{ entityVariable }}.{{ attribute.name }} = {{ trySyntax }} json => "{{ attributeKey }}"
|
32
|
+
{%- endif -%}
|
23
33
|
{%- else -%}
|
24
|
-
|
34
|
+
{%- if attribute.transformer.size > 0 %}
|
35
|
+
{{ entityVariable }}.{{ attribute.name }}.value = {{ trySyntax }} {{ attribute.transformer }}.decode(json => "{{ attributeKey }}")
|
36
|
+
{%- else %}
|
37
|
+
{{ entityVariable }}.{{ attribute.name }}.value = {{ trySyntax }} json => "{{ attributeKey }}"
|
38
|
+
{%- endif -%}
|
25
39
|
{%- endif -%}
|
26
40
|
{%- else -%}
|
27
|
-
{%- if attribute.transformer.size > 0
|
28
|
-
{{ entityVariable }}.{{ attribute.name }} =
|
29
|
-
{%- else
|
30
|
-
{{ entityVariable }}.{{ attribute.name }} =
|
41
|
+
{%- if attribute.transformer.size > 0 %}
|
42
|
+
{{ entityVariable }}.{{ attribute.name }} = {{ trySyntax }} {{ attribute.transformer }}.decode(json => "{{ attributeKey }}")
|
43
|
+
{%- else %}
|
44
|
+
{{ entityVariable }}.{{ attribute.name }} = {{ trySyntax }} json => "{{ attributeKey }}"
|
31
45
|
{%- endif -%}
|
32
46
|
{%- endif -%}
|
33
47
|
{%- else -%}
|
34
|
-
{%- if attribute.transformer.size > 0
|
35
|
-
{{ entityVariable }}.{{ attribute.name }} =
|
36
|
-
{%- else
|
37
|
-
{{ entityVariable }}.{{ attribute.name }} =
|
48
|
+
{%- if attribute.transformer.size > 0 %}
|
49
|
+
{{ entityVariable }}.{{ attribute.name }} = {{ trySyntax }} {{ attribute.transformer }}.decode(json => "{{ attributeKey }}")
|
50
|
+
{%- else %}
|
51
|
+
{{ entityVariable }}.{{ attribute.name }} = {{ trySyntax }} json => "{{ attributeKey }}"
|
38
52
|
{%- endif -%}
|
39
53
|
{%- endcase -%}
|
54
|
+
{%- endif -%}
|
40
55
|
{%- endfor -%}
|
41
56
|
|
42
|
-
{
|
43
|
-
|
57
|
+
{% for relationship in entity.relationships -%}
|
58
|
+
{%- if relationship.json_ignored == false %}
|
59
|
+
{%- assign relationKey = relationship.name -%}
|
60
|
+
{%- assign trySyntax = "try" -%}
|
61
|
+
{%- if relationship.optional == true -%}
|
62
|
+
{%- assign trySyntax = "try?" -%}
|
63
|
+
{%- endif -%}
|
44
64
|
{%- if relationship.json_key_path.size > 0 -%}
|
45
65
|
{%- assign relationKey = relationship.json_key_path -%}
|
46
66
|
{%- endif -%}
|
47
67
|
{%- if relationship.type == "to_many" -%}
|
48
|
-
|
68
|
+
{%- if relationship.optional == true %}
|
69
|
+
if let {{ relationship.name }}Sandbox: [{{ relationship.inverse_type }}] = {{ trySyntax }} json => "{{ relationKey }}" {
|
70
|
+
{{ entityVariable }}.{{ relationship.name }}.append(objectsIn: {{ relationship.name }}Sandbox)
|
71
|
+
}
|
72
|
+
{%- else %}
|
73
|
+
let {{ relationship.name }}Sandbox: [{{ relationship.inverse_type }}] = {{ trySyntax }} json => "{{ relationKey }}"
|
49
74
|
{{ entityVariable }}.{{ relationship.name }}.append(objectsIn: {{ relationship.name }}Sandbox)
|
50
|
-
{%- else -%}
|
51
|
-
{{ entityVariable }}.{{ relationship.name }} = try json => "{{ relationKey }}"
|
52
75
|
{%- endif -%}
|
76
|
+
{%- else %}
|
77
|
+
{{ entityVariable }}.{{ relationship.name }} = {{ trySyntax }} json => "{{ relationKey }}"
|
78
|
+
{%- endif -%}
|
79
|
+
{%- endif -%}
|
53
80
|
{%- endfor %}
|
81
|
+
|
54
82
|
return {{ entityVariable }}
|
55
83
|
}
|
56
84
|
|
@@ -1,12 +1,32 @@
|
|
1
1
|
{%- case attribute.type -%}
|
2
2
|
{%- when 'integer_16' or 'integer_32' or 'integer_64' -%}
|
3
|
-
0
|
3
|
+
{%- if attribute.default.size > 0 -%}
|
4
|
+
{{ attribute.default }}
|
5
|
+
{%- else -%}
|
6
|
+
0
|
7
|
+
{%- endif -%}
|
4
8
|
{%- when 'float' or 'double' or 'decimal' -%}
|
5
|
-
|
9
|
+
{%- if attribute.default.size > 0 -%}
|
10
|
+
{{ attribute.default }}
|
11
|
+
{%- else -%}
|
12
|
+
0.0
|
13
|
+
{%- endif -%}
|
6
14
|
{%- when 'string' -%}
|
7
|
-
|
15
|
+
{%- if attribute.default.size > 0 -%}
|
16
|
+
"{{ attribute.default }}"
|
17
|
+
{%- else -%}
|
18
|
+
""
|
19
|
+
{%- endif -%}
|
8
20
|
{%- when 'boolean' -%}
|
21
|
+
{%- if attribute.default.size > 0 -%}
|
22
|
+
{%- if attribute.default == "YES" -%}
|
23
|
+
true
|
24
|
+
{%- else -%}
|
25
|
+
false
|
26
|
+
{%- endif -%}
|
27
|
+
{%- else -%}
|
9
28
|
false
|
29
|
+
{%- endif -%}
|
10
30
|
{%- when 'date' -%}
|
11
31
|
Date()
|
12
32
|
{%- when 'binary' -%}
|
@@ -1,12 +1,32 @@
|
|
1
1
|
{%- case attribute.type -%}
|
2
2
|
{%- when 'integer_16' or 'integer_32' or 'integer_64' -%}
|
3
|
-
0
|
3
|
+
{%- if attribute.default.size > 0 -%}
|
4
|
+
{{ attribute.default }}
|
5
|
+
{%- else -%}
|
6
|
+
0
|
7
|
+
{%- endif -%}
|
4
8
|
{%- when 'float' or 'double' or 'decimal' -%}
|
5
|
-
|
9
|
+
{%- if attribute.default.size > 0 -%}
|
10
|
+
{{ attribute.default }}
|
11
|
+
{%- else -%}
|
12
|
+
0.0
|
13
|
+
{%- endif -%}
|
6
14
|
{%- when 'string' -%}
|
7
|
-
|
15
|
+
{%- if attribute.default.size > 0 -%}
|
16
|
+
"{{ attribute.default }}"
|
17
|
+
{%- else -%}
|
18
|
+
""
|
19
|
+
{%- endif -%}
|
8
20
|
{%- when 'boolean' -%}
|
21
|
+
{%- if attribute.default.size > 0 -%}
|
22
|
+
{%- if attribute.default == "YES" -%}
|
23
|
+
true
|
24
|
+
{%- else -%}
|
25
|
+
false
|
26
|
+
{%- endif -%}
|
27
|
+
{%- else -%}
|
9
28
|
false
|
29
|
+
{%- endif -%}
|
10
30
|
{%- when 'date' -%}
|
11
31
|
Date()
|
12
32
|
{%- when 'binary' -%}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gyro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- NijiDigital
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
name: liquid
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- - ~>
|
19
|
+
- - "~>"
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
|
-
- - ~>
|
26
|
+
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: '3.0'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: rspec
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
|
-
- - ~>
|
33
|
+
- - "~>"
|
34
34
|
- !ruby/object:Gem::Version
|
35
35
|
version: '3.5'
|
36
36
|
type: :development
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
|
-
- - ~>
|
40
|
+
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '3.5'
|
43
43
|
description: |2
|
@@ -149,17 +149,17 @@ require_paths:
|
|
149
149
|
- lib
|
150
150
|
required_ruby_version: !ruby/object:Gem::Requirement
|
151
151
|
requirements:
|
152
|
-
- -
|
152
|
+
- - ">="
|
153
153
|
- !ruby/object:Gem::Version
|
154
154
|
version: 2.0.0
|
155
155
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
|
-
- -
|
157
|
+
- - ">="
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: '0'
|
160
160
|
requirements: []
|
161
161
|
rubyforge_project:
|
162
|
-
rubygems_version: 2.
|
162
|
+
rubygems_version: 2.5.2
|
163
163
|
signing_key:
|
164
164
|
specification_version: 4
|
165
165
|
summary: Generate Realm.io models for Swift, Java & ObjC from xcdatamodel
|