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
@@ -1,234 +0,0 @@
1
- =begin
2
- Copyright 2016 - Niji
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- =end
16
-
17
- require 'nokogiri'
18
- require 'set'
19
- require File.expand_path('relationship', File.dirname(__FILE__))
20
- require File.expand_path('attribute', File.dirname(__FILE__))
21
-
22
- module Gyro
23
- module XCDataModel
24
- module Parser
25
- class Entity
26
-
27
- attr_accessor :name, :parent, :abstract, :attributes, :relationships, :identity_attribute, :comment
28
- alias_method :abstract?, :abstract
29
-
30
- def initialize(entity_xml)
31
- @name = entity_xml.xpath('@name').to_s
32
- @parent = entity_xml.xpath('@parentEntity').to_s
33
- @abstract = entity_xml.xpath('@isAbstract').to_s == 'YES' ? true : false
34
- @clean = false
35
- @identity_attribute = entity_xml.xpath(USERINFO_VALUE%['identityAttribute']).to_s
36
- @comment = entity_xml.xpath(USERINFO_VALUE%['comment']).to_s
37
- @attributes = Hash.new
38
- @relationships = Hash.new
39
- load_entity(entity_xml)
40
- end
41
-
42
- def to_s
43
- str = "\nEntity => #{@name}\n"
44
- @attributes.each do |_, attribute|
45
- str += attribute.to_s
46
- end
47
- @relationships.each do |_, relationship|
48
- str += relationship.to_s
49
- end
50
- str
51
- end
52
-
53
- def used_as_list_by_other?(entities)
54
- entities.each do |_, entity|
55
- entity.relationships.each do |_, relationship|
56
- return true if relationship.inverse_type == @name and relationship.type == :to_many
57
- end
58
- end
59
- false
60
- end
61
-
62
- def has_list_attributes?(inverse = false)
63
- @relationships.each do |_, relationship|
64
- return true if relationship.type == :to_many and (!inverse ? !relationship.inverse? : true)
65
- end
66
- false
67
- end
68
-
69
- def has_no_inverse_relationship?
70
- @relationships.each do |_, relationship|
71
- return true unless relationship.inverse?
72
- end
73
- false
74
- end
75
-
76
- def has_ignored?
77
- @attributes.each do |_, attribute|
78
- return true if attribute.realm_ignored?
79
- end
80
- @relationships.each do |_, relationship|
81
- return true if relationship.realm_ignored?
82
- end
83
- false
84
- end
85
-
86
- def has_primary_key?
87
- !@identity_attribute.empty?
88
- end
89
-
90
- def has_required?
91
- @attributes.each do |_, attribute|
92
- return true if is_required?(attribute)
93
- end
94
- false
95
- end
96
-
97
- def is_required?(attribute)
98
- unless attribute.optional?
99
- return true unless self.has_primary_key?
100
- return true if self.has_primary_key? && !attribute.name.eql?(identity_attribute)
101
- end
102
- false
103
- end
104
-
105
- def has_default_value?(attribute = @identity_attribute)
106
- attribute.name != @identity_attribute
107
- end
108
-
109
- def has_indexed_attributes?
110
- @attributes.each do |_, attribute|
111
- return true if attribute.indexed?
112
- end
113
- false
114
- end
115
-
116
- def has_json_key_path?
117
- @attributes.each do |_, attribute|
118
- return true unless attribute.json_key_path.empty?
119
- end
120
- @relationships.each do |_, relationship|
121
- return true if !relationship.inverse? and !relationship.json_key_path.empty?
122
- end
123
- false
124
- end
125
-
126
- def has_enum_attributes?
127
- @attributes.each do |_, attribute|
128
- return true unless attribute.enum_type.empty?
129
- end
130
- false
131
- end
132
-
133
- def transformers
134
- transformers = Set.new
135
- @attributes.each do |_, attribute|
136
- transformers.add attribute.transformer unless attribute.transformer.empty?
137
- end
138
- transformers
139
- end
140
-
141
- def has_custom_transformers?
142
- @attributes.each do |_, attribute|
143
- return true unless attribute.transformer.empty?
144
- end
145
- false
146
- end
147
-
148
- def need_transformer?
149
- has_enum_attributes? || has_bool_attributes? || has_custom_transformers? || has_date_attribute?
150
- end
151
-
152
- def has_bool_attributes?
153
- has_bool_attributes = false
154
- @attributes.each do |_, attribute|
155
- has_bool_attributes = true if attribute.type == :boolean
156
- end
157
- has_bool_attributes
158
- end
159
-
160
- def has_number_attributes?
161
- has_number_attributes = false
162
- @attributes.each do |_, attribute|
163
- if attribute.enum_type.empty?
164
- case attribute.type
165
- when :integer_16 then
166
- has_number_attributes = true
167
- when :integer_32 then
168
- has_number_attributes = true
169
- when :integer_64 then
170
- has_number_attributes = true
171
- when :decimal then
172
- has_number_attributes = true
173
- when :double then
174
- has_number_attributes = true
175
- when :float then
176
- has_number_attributes = true
177
- else
178
- has_number_attributes = false
179
- end
180
- break if has_number_attributes
181
- end
182
- end
183
- has_number_attributes
184
- end
185
-
186
- def has_date_attribute?
187
- @attributes.each do |_, attribute|
188
- return true if attribute.type == :date
189
- end
190
- false
191
- end
192
-
193
- def has_list_relationship?
194
- @relationships.each do |_, relationship|
195
- return true unless relationship.destination.empty?
196
- end
197
- false
198
- end
199
-
200
- def has_only_inverse?
201
- nb_inverses = 0
202
- @relationships.each do |_, relationship|
203
- nb_inverses+=1 if relationship.inverse?
204
- end
205
- nb_inverses==@relationships.size
206
- end
207
-
208
- private ################################################################
209
-
210
- def load_entity(entity_xml)
211
- load_attributes(entity_xml)
212
- load_relationships(entity_xml)
213
- end
214
-
215
- def load_attributes(entity_xml)
216
- entity_xml.xpath('attribute').each do |node|
217
- attribute = Attribute.new(node, @name)
218
- if attribute.type != 'Transformable'
219
- @attributes[attribute.name] = attribute
220
- end
221
- end
222
- end
223
-
224
- def load_relationships(entity_xml)
225
- entity_xml.xpath('relationship').each do |node|
226
- relationship = Relationship.new(node, @name)
227
- @relationships[relationship.name] = relationship
228
- end
229
- end
230
- end
231
-
232
- end
233
- end
234
- end
@@ -1,70 +0,0 @@
1
- =begin
2
- Copyright 2016 - Niji
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- =end
16
-
17
- require File.expand_path('../../xcdatamodel/parser/relationship', File.dirname(__FILE__))
18
-
19
- module Gyro
20
- module XCDataModel
21
- module Parser
22
-
23
- class Relationship
24
-
25
- attr_accessor :entity_name, :name, :type, :optional, :deletion_rule, :inverse_name, :inverse_type, :json_key_path, :support_annotation
26
- attr_accessor :realm_ignored
27
- attr_accessor :destination
28
-
29
- alias_method :realm_ignored?, :realm_ignored
30
-
31
- def initialize(relationship_xml, entity_name)
32
- @entity_name = entity_name
33
- @name = relationship_xml.xpath('@name').to_s
34
- @optional = relationship_xml.xpath('@optional').to_s
35
- @deletion_rule = relationship_xml.xpath('@deletionRule').to_s
36
- @inverse_name = relationship_xml.xpath('@inverseName').to_s
37
- @inverse_type = relationship_xml.xpath('@destinationEntity').to_s
38
- @json_key_path = relationship_xml.xpath(USERINFO_VALUE%['JSONKeyPath']).to_s
39
- @realm_ignored = relationship_xml.xpath(USERINFO_VALUE%['realmIgnored']).to_s.empty? ? false : true
40
- @support_annotation = relationship_xml.xpath(USERINFO_VALUE%['supportAnnotation']).to_s
41
- load_type(relationship_xml)
42
- @destination = relationship_xml.xpath(USERINFO_VALUE%['destination']).to_s
43
- search_for_error
44
- end
45
-
46
- def to_s
47
- "\tRelationship => name=#{@name} | type=#{@type} | optional=#{@optional} | deletion_rule=#{@deletion_rule}\n"
48
- end
49
-
50
- def inverse?
51
- @name.end_with?('_')
52
- end
53
-
54
- private ################################################################
55
-
56
- def load_type(relationship_xml)
57
- max_count = relationship_xml.xpath('@maxCount').to_s
58
- @type = (!max_count.nil? and max_count == '1') ? :to_one : :to_many
59
- end
60
-
61
- def search_for_error
62
- Raise::error("The relationship \"%s\" from \"%s\" is wrong - please fix it"%[name, entity_name]) if inverse_type.empty? && destination.empty?
63
- Raise::error("The relationship \"%s\" from \"%s\" is wrong - please set a 'No Value' relationship as 'To Many'"%[name, entity_name]) if !destination.empty? && type != :to_many
64
- end
65
-
66
- end
67
-
68
- end
69
- end
70
- end
@@ -1,59 +0,0 @@
1
- =begin
2
- Copyright 2016 - Niji
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- =end
16
-
17
- require 'nokogiri'
18
- require File.expand_path('../../utils/raise', File.dirname(__FILE__))
19
- require File.expand_path('entity', File.dirname(__FILE__))
20
-
21
- module Gyro
22
- module XCDataModel
23
- module Parser
24
- USERINFO_VALUE = "userInfo/entry[@key='%s']/@value"
25
-
26
- class XCDataModel
27
-
28
- attr_accessor :entities
29
-
30
- def initialize(xcdatamodel_dir)
31
- contents_file = File.join(xcdatamodel_dir, 'contents')
32
- Raise::error('Unable to find contents of xcdatamodel dir') unless File.exist?(contents_file)
33
- @entities = Hash.new
34
- file = File.open(contents_file)
35
- document_xml = Nokogiri::XML(file).remove_namespaces!
36
- file.close
37
- load_entities(document_xml)
38
- end
39
-
40
- def to_s
41
- str = String.new
42
- @entities.each do |_, value|
43
- str += value.to_s
44
- end
45
- str
46
- end
47
-
48
- private
49
-
50
- def load_entities(document_xml)
51
- document_xml.xpath('//entity').each do |node|
52
- entity = Entity.new(node)
53
- @entities[entity.name] = entity
54
- end
55
- end
56
- end
57
- end
58
- end
59
- end