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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a514835bd0ec32d1c3d435dacb35f57fcd5c67d3
4
- data.tar.gz: 3f295908353f89859d307f4757afd277ef2ce141
3
+ metadata.gz: 15960f1f9c3d4bdb80d4cd3edfb5a7380b79c72c
4
+ data.tar.gz: 58e1994395f309312e639e61287a80ae0a00514b
5
5
  SHA512:
6
- metadata.gz: 0dd5b55d23f50e1fd66e7bdddf75acbee534471c9d15434824ee1c43f970d10458ea799e6a517e1cdb9e8dea63043f8cdc3cb31c7bfbf8975fc97034f7ccaf25
7
- data.tar.gz: a47c9b8e4c73e2b34368371a4d08901faec7fcd4e2bce118f1e70adf03ff8d712bdf31504160063ae1bc7b5714d278d06c6ce04d842b94902851bb2a6956030a
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, 'support_annotation' => support_annotation,
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
@@ -15,5 +15,5 @@
15
15
  # Gyro Version
16
16
  #
17
17
  module Gyro
18
- VERSION = '1.0.1'.freeze
18
+ VERSION = '1.1.0'.freeze
19
19
  end
@@ -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 -%}
@@ -6,7 +6,7 @@
6
6
  {%- else %}
7
7
  {%- if relationship.destination.size == 0 %}
8
8
  {%- if relationship.type != "to_many" -%}
9
- {{ relationship.inverse_type }}
9
+ {{ relationship.inverse_type }}
10
10
  {%- else -%}
11
11
  RealmList<{{ relationship.inverse_type }}>
12
12
  {%- endif %}
@@ -5,7 +5,7 @@
5
5
  {%- else -%}
6
6
  {%- if relationship.destination.size == 0 -%}
7
7
  {%- if relationship.type != "to_many" -%}
8
- {{ relationship.inverse_type }}
8
+ {{ relationship.inverse_type }}
9
9
  {%- else -%}
10
10
  RealmList<{{ relationship.inverse_type }}>
11
11
  {%- endif -%}
@@ -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
- {% assign attributeKey = attribute.name -%}
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 }} = try Date.decode(json => "{{ attributeKey }}")
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.transformer.size > 0 -%}
22
- {{ entityVariable }}.{{ attribute.name }}.value = try {{ attribute.transformer }}.decode(json => "{{ attributeKey }}")
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
- {{ entityVariable }}.{{ attribute.name }}.value = try json => "{{ attributeKey }}"
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 }} = try {{ attribute.transformer }}.decode(json => "{{ attributeKey }}")
29
- {%- else -%}
30
- {{ entityVariable }}.{{ attribute.name }} = try json => "{{ attributeKey }}"
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 }} = try {{ attribute.transformer }}.decode(json => "{{ attributeKey }}")
36
- {%- else -%}
37
- {{ entityVariable }}.{{ attribute.name }} = try json => "{{ attributeKey }}"
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
- {%- for relationship in entity.relationships %}
43
- {% assign relationKey = relationship.name -%}
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
- let {{ relationship.name }}Sandbox: [{{ relationship.inverse_type }}] = try json => "{{ relationKey }}"
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
- 0.0
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' -%}
@@ -58,4 +58,4 @@ final class Product: Object {
58
58
 
59
59
  let users = List<Users>()
60
60
  }
61
- ```
61
+ ```
@@ -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
- 0.0
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.1
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.4.7
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